Async/Await Under the Hood
async functions don't run on magic threads — they compile into state machines whose
suspension points become enum states and whose locals live on a heap-allocated future.
This video decompiles a simple async function, then shows what happens at an await:
the future polls, returns Pending, and is re-polled by an executor when I/O completes.
Topics covered:
- What
async fncompiles to: a struct of locals plus a state enum - Polling: every await point becomes a match on a state
- The Pending vs. Ready contract and how the executor drives futures
- Where suspended state lives: the heap-allocated future vs. the stack
- Wakers: how I/O tells the executor a future can progress
- Executors: one thread vs. a worker pool
- Rust futures, JavaScript promises, and Kotlin coroutines: the same model
- Why async is fast: no thread per task
Related articles
Event Loops vs Threads: How Concurrency Actually Gets Scheduled
Why one thread with non-blocking I/O beats ten thousand blocked threads, how epoll and kqueue do readiness checking, the event loop fairness problem, and Go's M:N scheduler.
Boxing, Unboxing, and Value vs Reference Semantics
Why every boxed int is a heap allocation, why int[] beats ArrayList and Integer[] by 4-16x, how Java generics erasure forces boxing, and how C# structs avoid it.
Branch Prediction and CPU Pipelines: Why Sorted Data Is Faster
How the branch target buffer, speculative execution, and pipeline flushes make sorted arrays up to 10x faster, and why __builtin_expect, retpolines, and Spectre mitigations exist.
More in Runtime & Execution
How Garbage Collection Actually Works
A visual walkthrough of mark-sweep, generational collection, and concurrent GC — the algorithms that keep your memory clean.
WatchWhat Your Code Does Before main()
The loader, the linker, the dynamic linker, and the runtime — everything that happens between pressing run and your first line of code.
WatchHow Threads Actually Work
The kernel scheduler, context switches, goroutines versus threads — a visual walkthrough of what 'running on a core' really means.
WatchVirtual Machines Explained
How language VMs like the JVM and the CLR work — bytecode verification, the execution engine, and the runtime services beneath your program.
DetailsInterpreters vs. Compilers
What an interpreter actually does at runtime versus what a compiler does before — ASTs, bytecode, and why the boundary keeps blurring.
DetailsReference Counting vs. Tracing GC
The two families of automatic memory management — refcounts, cycles, and ARC versus tracing collectors, roots, and reachability — compared on real trade-offs.
DetailsStack vs. Heap Memory
Where your variables actually live — the hardware stack's push and pop discipline versus the heap's malloc and free — and why the difference matters.
DetailsThe Event Loop, Visualized
How Node.js and the browser run one thread with many tasks — the call stack, the task queue, and microtasks — animated frame by frame.
DetailsJIT Compilers Explained
How just-in-time compilers work — profiling, tiered compilation, and generating machine code at runtime — from interpreter to native in microseconds.
DetailsDepth, delivered weekly
One technical dispatch a week — articles and episode notes before they go public.
One technical dispatch per week. No noise.