You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once upon a time (~10 years ago) the Go compiler would merge temporaries on the stack (https://golang.org/cl/12829043). At some point, however, this optimization was removed.
Stack space is generally cheap compared to heap space (since it doesn't generally increase the rate of garbage collection), but in some circumstances, the lack of merged temporaries can lead to a substantial amount of stack space waste.
Some applications have a lot of stacks floating around (e.g. Kubernetes' API server, via "watch" requests), in which case the cost is direct: additional memory use. Another cost is that a larger stack may means more stack growth, which takes CPU time. Lastly, the GC has to scan these stacks, and while the cost mostly proportional to the number of live pointers on the stack, the GC would still have less work to do overall for each stack.
Work by Uber and Kubernetes has shown that stack space overheads can be significantly reduced by manually re-scoping named variables.
It would be tricky to change the locations of pointers on the stack mid-function, but we can at least merge stack slots where the pointer/scalar data (GC shape) is the same. Credit to @mdempsky for the idea for reviving this.
This is a more general version of #62077, which focuses on aggregates.
The text was updated successfully, but these errors were encountered: