Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: merge temporaries and named variables by GC shape #62737

Open
mknyszek opened this issue Sep 19, 2023 · 0 comments
Open

cmd/compile: merge temporaries and named variables by GC shape #62737

mknyszek opened this issue Sep 19, 2023 · 0 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mknyszek
Copy link
Contributor

mknyszek commented Sep 19, 2023

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.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 19, 2023
@mknyszek mknyszek added this to the Backlog milestone Sep 20, 2023
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: Todo
Development

No branches or pull requests

3 participants