Go Stack: Should It Be Moving Like That?
summary
Built a production Go debugger with runtime hacks that forces deep runtime reading, revealing concrete mechanics: goroutine stacks start at 2 KB initial stack versus OS threads' 1–10 MB, the compiler inserts prologue/epilogue checks that call morestack doubles stack to grow stacks, and the runtime uses per-g metadata and stack guard offsets to relocate pointers during copy. Escape analysis moves small locals to the heap, increasing GC cost; the GC later calls shrinkstack when usage falls below one quarter.
AI-written summary · about
chapters (7)
- 0:00Introduction to Go stack
- 3:24Stack growth in Go
- 11:58How Morestack works
- 16:39Pointers and stack vs heap
- 19:30Why understanding runtime matters
- 23:04Performance and trade-offs in Go
- 24:32Go runtime insights and conclusion
related talks
30mGo: escape analysis
22mUnderstanding Allocations: the Stack and the Heap
50mUnderstanding the Go runtime
30mMemory Management in Go: The good, the bad and the ugly
46mUnderstanding the Go runtime
50mAn insight into Go Garbage Collection
38mUnderstanding Memory Allocation in Go
28mHow to Win Frames and Influence Pointers
