"Slice Recycling Performance and Pitfalls"
summary
Claim: recycling byte slices drastically cuts GC time and peak heap versus throwing allocations away. Experiment builds a tiny encoder and four memory managers — null, sync.Pool, power-of-two bins, reserve strategy — and measures with benchmarks, parsed GC debug lines for max-heap, CPU flame graphs via go tool pprof and the trace web UI. Results show ~order-of-magnitude runtime and heap differences, reserved is fastest, null worst, and a leaky sync.Pool converges to reserved behavior if starting capacity is large.
AI-written summary · about
chapters (26)
- 0:00Intro
- 0:55What is garbage
- 1:19Garbage collector job
- 1:29Flame graph
- 3:06Slices
- 3:19Garbage Collector
- 3:50Sink Pool
- 4:13Trash
- 4:40Undefined order
- 5:03Container size
- 5:27The pen
- 6:15The encoder
- 7:16The interface
- 7:36The pool
- 7:46The abstraction
- 8:04The four strategies
- 8:32Null strategy
- 9:47Sync strategy
- 11:25Power of Two strategy
- 12:13Reserved strategy
- 13:34Four ways to analyze performance
- 15:33Benchmarking
- 17:08Profiling
- 18:07Tracing
- 20:16Naive Approach
- 20:50Visualization
related talks
50mAn insight into Go Garbage Collection
30mMemory Management in Go: The good, the bad and the ugly
51mObscure Go Optimisations
48mGolang's Garbage
21mGo Right Ahead! Simple Hacks to Cut Memory Usage by 80&
19mHeap Optimization for Go Systems
40mGolang memory footprint
30mBalanced GC: A Copying Garbage Collector for Golang
