-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: anonymous structs consume space in binary #38291
Comments
This could maybe help with smaller binaries. /cc @josharian @randall77 |
Instead of adding all the fields as part of the name could we take the variables package path and variables name and add a prefix or suffix that can only be generated by the compiler? |
This is probably interesting to @bradfitz too, particularly the runtime example saving 5KiB. |
@martisch just to clarify, I wasn't proposing fixing all these manually :D. It's something that compiler/linker could do. And yeah, my thoughts were along the same line, A) use variable name for instead of the string description or B) generate dynamically the name when needed and use some hash in the binary. |
It turns out we just significantly improved this! Commit 44d2286 drops type descriptors that aren't used, which means these long symbols names and many other things no longer appear in the binary. This shrinks cmd/compile by 140 KiB. There's still more that could be done. If you put a large anonymous type in an interface, the linker will still pull in the type descriptor and all of these large symbol names. On our list of things to explore in the linker (not for 1.15) is to use structural hashes to name and dedup type symbols. The downside, of course, is that the type symbol names in the binary become much less informative. |
Moving to unplanned since we fixed a lot of this problem for 1.15, and exploring further improvements is on the list for the linker, but involves trade-offs that need to be explored. |
I can confirm that on tip the |
Anonymous structs can take quite a significant amount of space in the compiled binary. Since anonymous structs do not have a proper name hence the full anonymous struct description used as the name.
As a quick experiment, by replacing some anonymous structs in Go compiler with a named type the compiler shrunk 14KB and the gofmt shrunk by 10KB.
As an extreme example: by changing:
go/src/runtime/mgc.go
Line 945 in 553a862
Related issues #6853, #36313
Go Version
The text was updated successfully, but these errors were encountered: