Coroutines vs. Threads: The True Cost of a Context Switch
summary
Explains that kernel-level context switches involve syscalls, a kernel trap, the scheduler saving registers and triggering CPU cache invalidation, while suspending coroutines just store a tiny continuation object on the heap and return to their dispatcher. Proves it live by measuring with the Android Studio Profiler, launching 100,000 coroutines which complete, then showing the app fail when attempting raw threads (the uploader notes the app dies under the weight of few hundred threads crash). Emphasizes dispatchers, scopes, and suspension as the real cost controls.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 1:42Threads and OS overhead
- 6:13Thread definition and costs
- 8:41Thread blocking
- 11:50Cache misses and context switch
- 14:18Threads do not scale
- 15:23Coroutines reduce overhead
- 17:09Coroutine anatomy
- 20:01Live demo: coroutines vs threads
- 24:33Summary comparison
- 25:15Coroutine best practices
- 33:26Never block main thread
- 34:29Choosing dispatcher
- 37:19Key takeaways








