Understanding Escape Analysis to Speed Up Your Code
summary
Compares two string-search implementations with benchmarks and memory profile (p.out -> pprof) output, showing one version originally does ~53 bytes and two allocations while the alternative runs as a zero allocation algorithm. Uses go test -bench, go tool pprof and an escape analysis report via GC flag -M2 to find an interface conversion and an inlining decision that forces a heap escape. After replacing the io interface with direct method calls allocations disappear and latency drops from ~600ns to ~300ns, but the other algorithm still runs ~100% faster.
AI-written summary · about
chapters (9)
- 0:00The elvis replacement story
- 1:31Comparing alternative code
- 2:58Benchmarking the algorithms
- 4:24Memory profiling results
- 5:53Escape analysis investigation
- 7:28Optimizing with polymorphism
- 11:20Achieving zero allocations
- 14:09Compiler optimization tricks
- 16:10Final profiling and takeaway
related talks
26mPractical Memory Profiling
40mTwo Go programs, three different profiling techniques, all in 40 minutes
22mMEA2: a Lightweight Field-Sensitive Escape Analysis with Points-to Calculation for Golang
30mGo: escape analysis
51mObscure Go Optimisations
29mOptimizing Go Code Without a Blindfold
14mOptimizing Go code without a blindfold
19mHeap Optimization for Go Systems
