Optimizing Go code without a blindfold
summary
A tiny slice-copy change from append to prealloc plus index assignment yields about 70% faster and far fewer allocations, while a real JSON decoder benchmark runs ~10 ms per input (~200 MB/s) but bounces ±3–4% so a 1% win is lost in noise. Use benchstat to collect many samples and report variance, and use perflock to pin CPU clocks (example: run at 70% to avoid turbo throttling). Also watch out for multiple testing false positives.
AI-written summary · about
chapters (9)
- 0:00Introduction to optimizing Go
- 2:07Benchmarking basics in Go
- 3:32Noise in benchmarks and statistics
- 7:28CPU throttling and pareflock
- 11:17Recap of tools and compiler tricks
- 13:05Compiler insights and escape analysis
- 15:36Code alignment and compiler improvements
- 17:47Compiler internals with SSA
- 18:37Q&A on benchmarking environments
related talks
14mOptimizing Go code without a blindfold
29mOptimizing Go Code Without a Blindfold
51mObscure Go Optimisations
40mProfiling real-world golang service
26mPractical Memory Profiling
38mSo You Wanna Go Fast?
40mTwo Go programs, three different profiling techniques, all in 40 minutes
21mUnderstanding Escape Analysis to Speed Up Your Code
