Micro-Optimization for Fun and Profit
summary
Builds a simplified Cats Effect IO runtime (IO values, errors, async, fibers) and measures five micro-optimizations with JMH benchmarks on EC2 t2.large (warns against Apple Silicon). Implements an IO fiber with a continuation stack and then: replaces linked lists with an array-backed stack, encodes continuations as bytes for allocation-free continuations, removes Either allocations, adds integer tag dispatch, and hoists current IO into a parameter. Results show ~60–70% speedups overall, but a surprising 4x regression for left-associated flatMap; trade-offs acknowledged.
AI-written summary · about
chapters (45)
- 0:00Intro
- 0:32Dont microoptimize
- 1:10Simplified IO
- 1:53GitHub
- 4:36Physical Factors
- 5:29Layers of abstraction
- 6:29Happy paths and unhappy paths
- 7:39What is slow
- 9:52What is fast
- 13:10Pro tip
- 14:25Implementing IO
- 15:39IO Fiber
- 16:38IL Fiber
- 17:40Run
- 18:46Continue
- 19:39Async
- 20:34Measuring
- 20:59SBTJMH
- 24:23Micro Benchmarks
- 27:05Micro Optimizations
- 27:22Allocation Free Stack
- 27:35Continuation Stack
- 29:01Dynamic Arrays
- 30:57Array Stack
- 32:35Array Copy
- 32:47Benchmarks
- 33:03Why did it get worse
- 33:17The results
- 33:35Why I tried different array bounds
- 35:14The problem with micro benchmarks
- 35:58Optimization for fun
- 36:28The answer
- 37:24The solution
- 40:10Bias
- 40:31Allocation Free Results
- 41:34Encoding
- 42:56Results
- 43:08Pattern Matching
- 43:35If Else
- 44:26Deftag
- 45:24Invoke Virtual
- 46:51More Stack Less Game
- 47:10Current
- 48:12Faster
- 48:54Takeaways
related talks
36mProject Loom
45mMinimal Values Under the Hood
53mFrom functional programming to assembly - the cost of abstractions....
46mHow difficult can it be to write efficient code?
02h 36mJava keeps throttling up!
51mGame of Loom: implementation patterns and performance implications playing with
51mJava at Speed: Getting the Most Out of Modern Hardware
55mNew Bytecodes, New Objects
