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: inline reflect.TypeOf (or make it intrinsic) #16869
Comments
/cc @josharian |
That's a lot of reflect.TypeOfs. |
@robpike, this is generated code from something akin to our protocol buffers or google-api-go-client. So it's the sort of auto-generated gobbledygook you might expect. |
Compiler seems to be inlining
|
@bradfitz does that means that something similar to
should lead to no calls to reflect.TypeOf at all ? |
@egorse, correct. No calls to reflect.TypeOf. Currently with your example code I see:
|
Note that there are actually two separate things here: treating reflect.TypeOf as an intrinsic, and handling reflect.TypeOf when generating static data. I think we should do both, and I just encountered some hot code in which the former would help. Note that treating reflect.TypeOf as an intrinsic is better than inlining it, because we can avoid creating an interface value, which often allocates. (Purity analysis might also help here, but reflect.TypeOf is a great intrinsic candidate anyway.) |
@randall77, I ran into this again. Know anybody on the compiler team who is looking for a project? :) |
So
The inlined code isn't great either, in that it doesn't realize that it doesn't need the data word of the interface, just type word, so it is still calling one of the |
@randall77 was mentioning the compiler maybe inlining reflect.TypeOf calls the other day. Or somebody was.
Today I ran across the github.com/vmware/govmomi/vim25/types package which has 5769 calls to reflect.TypeOf, populating a map:
If the compiler could inline the
reflect.TypeOf
calls then they could stop autogenerating the Elem part too, and it's all just static data and their init load could drop a bunch.reflect.TypeOf is just:
Low priority.
The text was updated successfully, but these errors were encountered: