| ▲ | masklinn 3 days ago | ||||||||||||||||||||||||||||||||||||||||
> Go won’t put large allocations on the stack even if escape analysis would permit it Depends what you mean by “large”. As of 1.24 Go will put slices several KB into the stack frame:
Goes on the stack if it does not escape (you can see Go request a large stack frame)
goes on the heap (Go calls runtime.makeslice).Interestingly arrays have a different limit: they respect MaxStackVarSize, which was lowered from 10MB to 128 KB in 1.24. If you use indexed slice literals gc does not even check and you can create megabyte-sized slices on the stack. | |||||||||||||||||||||||||||||||||||||||||
| ▲ | Yokohiii 3 days ago | parent [-] | ||||||||||||||||||||||||||||||||||||||||
There is a option -smallframes that seems to be intended for conservative use cases. Below are the related configs and a test at what point they escape (+1).
Not sure how to verify this, but the assumption you can allocate megabytes on the stack seems wrong. The output of the escape analysis for arrays is different then the make statement:
Maybe an overlook because it is a bit sneaky? | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||