Heap Optimization for Go Systems
summary
GODEBUG=gctrace=1 plus runtime.MemStats and pprof heap profiles identify GC spikes and show whether p99 latency correlates with collections. Replacing string map keys with a struct of three IDs drops ~26 million heap objects (~20% reduction), field pruning and reordering shrink per-object size from 64 to 24 bytes, and object pools lower allocation bursts when safe. Focus is on memstats and pprof flame graphs, GODEBUG gctrace, concrete reductions in object counts and bytes, and choosing value vs pointer layouts to cut GC scanning.
AI-written summary · about
chapters (12)
- 0:00Intro
- 0:46How does memory management in Go work?
- 2:07How does GC impact performance?
- 3:02What causes GC pressure?
- 4:38How to determine if GC is the problem? High tail latency Set the GODEBUG environment variable to see GC stats
- 7:17How to profile heap usage?
- 12:08How can we limit the impact of GC? Lower the number of objects on heap
- 12:41Reduce long-living heap objects
- 14:21Impact of removing strings
- 14:55Reduce the rate of allocation
- 15:34Clean up unused data fields
- 16:28Reorder fields for proper data alignment
related talks
48mGolang's Garbage
50mAn insight into Go Garbage Collection
30mMemory Management in Go: The good, the bad and the ugly
51mEvolving the Go Memory Manager's RAM and CPU Efficiency
30mGo: escape analysis
21mGo Right Ahead! Simple Hacks to Cut Memory Usage by 80&
40mProfiling real-world golang service
51mObscure Go Optimisations
