~/talk

Coroutines vs. Threads: The True Cost of a Context Switch

Talkat droidCon USA 2026 · on Friday, 2026-07-17· at 15:50· W222 B· [concurrency, android]
slides:none on file

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

  1. 0:00Introduction
  2. 1:42Threads and OS overhead
  3. 6:13Thread definition and costs
  4. 8:41Thread blocking
  5. 11:50Cache misses and context switch
  6. 14:18Threads do not scale
  7. 15:23Coroutines reduce overhead
  8. 17:09Coroutine anatomy
  9. 20:01Live demo: coroutines vs threads
  10. 24:33Summary comparison
  11. 25:15Coroutine best practices
  12. 33:26Never block main thread
  13. 34:29Choosing dispatcher
  14. 37:19Key takeaways
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.