How does Go handle stack growth for goroutines, and what are 'segmented stacks' vs. 'contiguous stacks'?
Last updated
Goroutines start with ~2KB stacks. A function prologue check detects overflow, then the runtime allocates a larger contiguous stack, copies it and fixes pointers (stacks can also shrink).
Old segmented stacks linked separate chunks, causing the hot-split problem: calls at a segment boundary in a loop repeatedly allocated and freed segments.
Contiguous stacks (since Go 1.3) eliminate hot-split, at the cost of an amortized, predictable copy on growth.