A deep dive into dispatching techniques
summary
A small stack bytecode interpreter is built and benchmarked (recursive Fibonacci) using hyperfine and perf with assembly inspection; a switch dispatch measures about 460 ms on a 2020 Apple Mac Mini M1 while token/label threading and tail-call chaining cut runtime roughly in half on that CPU by improving branch prediction and keeping state in registers. perf shows branches and branch misses dominate; on a cheap ThinkPad 2016 the switch wins because branch‑target prediction is poor. Measure on target, inspect assembly, and pick the technique that actually helps.
AI-written summary · about
chapters (14)
- 0:00Introduction
- 1:03Dispatch loop and bytecode interpreters
- 8:26Basic dispatch with switch
- 13:45Branch prediction in dispatch loops
- 15:52Call threading to avoid branches
- 19:01Token threading and computed goto
- 23:57Tail calls and register optimization
- 29:13Register keyword limitations
- 31:44Slow paths and register spilling
- 36:17Benchmarking on hardware
- 39:45Advanced dispatching techniques
- 42:30Inline dispatch and JIT compilation
- 42:51Key takeaways and final advice
- 51:20Q&A
related talks
45mBack to Front and Beyond
38mBoost Delivery Stream with Code Discipline Engineering
42mLet the Main Thread Breathe!
13mDemo: RISC-V as an Enabler of Heterogeneous Compute
33mScaling Swift Development
30mVisualizing process evolution
42mGame of Threads - You Spawn or You Die
36mPerformance for the long haul
