DoorDash Nov 9, 2021

The Beginner's Guide to Kotlin Coroutine Internals

Article Summary

Sonic Wang from DoorDash breaks down Kotlin coroutines from bytecode to scheduler. If you've ever wondered what actually happens when you call 'suspend', this deep dive reveals the magic.

DoorDash migrated from Python to Kotlin for backend services, requiring engineers to master coroutines quickly. This guide examines coroutines through three lenses: language compilation, standard library classes, and runtime scheduling. Wang uses bytecode inspection and decompilation to show exactly how coroutines work under the hood.

Key Takeaways

Critical Insight

Coroutines are lightweight, resumable tasks compiled into static JVM methods with state machines that enable cheap concurrent execution compared to traditional threading.

The article reveals why Dispatchers.Unconfined behaves differently only until the first suspension point, and what that means for your code.

Recent from DoorDash

Related Articles