Currently:
- All stack sizes are a power of 2.
- The minimum size is 2KB, hardcoded.
- We reserve ~800 bytes of goroutine stacks for the runtime.

So 1KB stacks are feasible, but just barely. I don't think you could fit 
much of a goroutine in 200 bytes of stack.

So smaller sizes are possible, but not really practical. We'd have to 
handle non-power-of-2 sizes, or shrink the runtime reservation, both of 
which might be a lot of work. (We've been working on the runtime 
reservation for years, and that number always seems to go in the wrong 
direction.)

A goroutine is both a stack and a goroutine descriptor. Those descriptors 
themselves are 392 bytes, so even if the stack was super tiny we still have 
at least that memory overhead per goroutine.
On Thursday, February 2, 2023 at 11:53:54 AM UTC-8 Elad Gavra wrote:

> Hi,
> I understand go uses an average metric to predict stack size required for 
> new go routines. Does it have minimum size?
> I was wandering if go optimizes "static stack size"? i.e. there are cases 
> where the code is predictable and the compiler can analyze the stack size 
> required for routines. In these cases the compiler can calculate the exact 
> size that will be required by the routine (or its upper bound). The size 
> could be even lower than the minimal (?) 2k.
>
> Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/bf8f758a-3466-40e2-95d1-8c7972d66406n%40googlegroups.com.

Reply via email to