Why do Go routines take up just 2KB space while threads take up 1MB? ⚡
The core reason for this efficiency is because goroutines are stackless. Whenever a regular thread is created, it gets its own stack (with a copy of all local data) while a goroutine does not.
Instead, all goroutines share the stack with the Go runtime. By sharing the stack, the Go runtime avoids the overhead or allocation and copying of the data.
This is a high-level overview of the stackless design, and I have written a detailed answer on Duggup, where I was asked this question by Vikhyat.
Read the complete answer - https://lnkd.in/ghPztKeU
⚡ I keep writing and sharing these engineering nuggets, so if you are keen on learning them, follow along.
duggup.com/arpit