Obscure Go Optimisations
summary
Shows how a hidden conversion silently allocates when Go casts a slice to an interface, causing Prometheus startup to do a million allocations and lose ~25% (profile showed a mystery confTslice allocating, then fix hoists a pointer out of the loop and removes GBs of allocation). Demonstrates profiler + flamegraph to find it, switching from interface calls to a function or type-parameterized compare, using PDQ sort and golang.org/x/slices for big wins, and replacing heat-ballast with GOMEMLIMIT + GOGC=off to drop GC frequency (example: GC rate 150→30 Hz and latency ~55ms→<40ms).
AI-written summary · about
chapters (8)
- 0:00Introduction and Background
- 5:43Identifying Performance Issues
- 13:26Optimizing Memory Allocation
- 19:06Sorting and Interface Overhead
- 25:48Generic Functions for Speed
- 32:26Understanding Garbage Collection
- 40:01Heap Management Techniques
- 45:02Conclusion and Key Takeaways
related talks
14mOptimizing Go code without a blindfold
40mTwo Go programs, three different profiling techniques, all in 40 minutes
40mGolang memory footprint
44mGo Profiling and Observability from Scratch
48mGolang's Garbage
29mOptimizing Go Code Without a Blindfold
30mMemory Management in Go: The good, the bad and the ugly
26mPractical Memory Profiling
