-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: generic function increases binary size #70215
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
Comments
Related Issues and Documentation (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
Why do you expect that? Generic functions are fundamentally more complex than non-generic ones, and an executable contains all kinds of bookkeeping information (e.g. for debugging) beyond the object code itself, so it shouldn't be surprising that the generic version results in a larger file in some cases. |
This is not a large enough problem to worry about. |
Can you give an a priori (principled, not empirical) rebuttal to my argument? |
@adonovan You asked why I expected that. And the reason is that I would have expected whatever bookkeeping should apply to all generic functions. But clearly that's not what happens (somehow). I don't think it's unreasonable to expect the compiler to work in a consistent fashion, or be surprised when it doesn't, especially because in this case it seems as though the compiler is forgetting to optimize something away. Whether this is some known or intentional limitation of the compiler or whatnot is not something I would be privy to. |
If you can find a specific element of the file that you think should have been optimized away but was not, then please do report a bug. But my point is that file size increases per se are not surprising. |
Go version
go version go1.22.8 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
I created two variations of a function - one that is generic and one that is not - and compared the resulting binary size.
What did you see happen?
The version that uses generics is 32 bytes larger for some reason.
I have tested a few other variants of generic vs. non-generic function, but have not reproduced this issue with any of them. There seems to be something peculiar about this particular function.
What did you expect to see?
There should not be any size difference.
The text was updated successfully, but these errors were encountered: