A closer look at garbage collection in Go
summary
Walks through real runs on 4,000 synthetic RSS files using go tool trace and browser tracing. Sequential run takes 2.5s, finds the term 28,000 times, does 232 GCs totaling ~67ms (avg 291Β΅s). Naive concurrency with 4,000 goroutines drops runtime to 751ms but triggers just 23 GCs that cost ~153ms (avg ~6ms), so GC is ~30% of time. Bounded parallelism via runtime.NumCPU and a buffered channel stabilizes heap and shifts GC behavior; toggling GOGC shows the expected ~180ms runtime change.
AI-written summary Β· about
chapters (10)
- 0:00Introduction to garbage collection
- 1:03Sequential algorithm walkthrough
- 3:36Analyzing trace with Go tool
- 7:55Sequential GC performance
- 8:37Building concurrent version
- 14:16Concurrent GC performance
- 18:14Optimizing goroutine count
- 21:47Stable heap with 12 goroutines
- 24:15GC cadence and trade-offs
- 25:38Q&A on GC impact
