Goroutines' 2KB Stack vs. C++ Threads' 1MB+ Footprint

Go's goroutines are significantly more lightweight, starting with a minimal stack size of approximately 2KB and dynamically growing, allowing Go applications to efficiently manage millions of concurrent goroutines. In contrast, C++ threads typically allocate a fixed stack of 1MB or more (often 8MB on Linux by default), limiting practical concurrency to thousands before exhausting system memory.

The top 3

  1. Go's M:N Scheduler: Stack Efficiency: Go's runtime employs an M:N scheduler to multiplex numerous lightweight goroutines onto a smaller pool of OS threads, enabling their compact 2KB initial stack size and efficient user-space management.
  2. Max Concurrent Tasks: Go's Million-Scale Edge: Go's lightweight 2KB goroutines enable a single server to manage hundreds of thousands to millions of concurrent tasks, a scale largely impractical for C++ OS threads with 1MB+ stacks that would quickly exhaust memory.
  3. RAM Footprint: Go's 500x Efficiency Advantage: With a starting 2KB stack compared to C++ threads' typical 1MB+ fixed footprint, Go goroutines are up to 500 times more memory efficient. This drastically reduces RAM requirements, leading to lower infrastructure costs and higher concurrency density per gigabyte in cloud deployments.

Sources

Open the full topic