Explaining Different Coroutine Flavours using Scala Native
summary
Explains concrete differences between stackless vs stackful coroutines, shows LLVM intrinsics used (eg llvm.coro.begin and coro suspend that returns -1/0/1) and contrasts state-machine/CPS lowering with copying stacks or using dedicated stacks. Demonstrates a Scala Native prototype that uses setjmp/longjmp style context switches for fibers and mentions an existing PR implementing a boundary suspend continuation for Scala Native. Quantifies tradeoffs: stackless is cheapest but requires code transforms, stackful supports arbitrary suspension but incurs copy or per-fiber stack overhead.
AI-written summary · about
chapters (19)
- 0:00Welcome
- 1:14Motivation for coroutines
- 2:17Coroutine classification
- 3:42Cooperative vs subroutines
- 5:07Stackless coroutines
- 8:16Continuation passing style
- 8:59Stackful coroutines
- 10:23Coroutines and async
- 11:48Memory execution
- 13:34State persistence
- 16:48Fibers and stack
- 18:56Context switching
- 20:25Coroutines in Scala Native
- 22:11LLVM lowering phases
- 25:24Implementing coroutines
- 29:23Stackful with setjmp/longjmp
- 33:20Stackful prototype
- 35:06Virtual threads prototype
- 36:30Call to action
related talks
45mDeep Dive into Coroutines on JVM
11mKotlin Coroutines: Design and Implementation
43mCoroutines for Java Developers
38mCoroutines Internals: How The Sausage is Made
39mCoroutine Suspension Mechanics
30mExploring JVM Innovations Through the Lens of Scala Native
47mKotlin Coroutines Reloaded
45mCoroutines: Kotlin Versus
