-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: code generated by generics seems inefficient #64699
Comments
The implementation of your method is in the shaped version. The concrete type version is just a wrapper which calls into the shape version. (That call may be inlined in some cases, so the implementation of your method may be in the concrete type version, but only when your method body is small.) The wrapper exists mostly for method tables, to inject a dictionary argument before calling into the shaped method.
Right. The shaped method is intended to handle all instantiations with the same-shaped argument. So if you had a
Yes, that's unused here. It's only a wrapper intended for method tables, like if you put See https://go.googlesource.com/proposal/+/refs/heads/master/design/generics-implementation-gcshape.md for gory details. I'm going to close this, as it is working as intended. Changes to this implementation would require more than just a bug. |
@randall77 but what can be smaller than this method which doesn't get inlined?
|
The inlining that could happen is |
Go version
go1.21.3 darwin/arm64
What operating system and processor architecture are you using (
go env
)?What did you do?
The following simple application:
most importantly it does indirect call of myVal.GetValue() (not speaking about missing inline possibility):
a) why it is calling
main.(*Array[go.shape.struct {}]).method(SB)
instead concrete typemain.(*Array[main.myVal]).method
?b)
main.(*Array[go.shape.struct {}]).method
doesn't exploit knowledge of concrete type (myVal) and performs indirect call to GetValue():c) what is even more stranger, compiler generates unused concrete type
main.(*Array[main.myVal]).method
but it doesn't exploit type knowledge as well and instead callsmain.(*Array[go.shape.struct {}]).method(SB)
:would appreciate some hints why code is generated this way and why expected optimizations are not performed.
What did you expect to see?
ideally, inlining of GetValue() method and simply passing const 5 to fmt.Printf().
less ideally direct call of myVal.GetValue() in method()
What did you see instead?
indirect call, not concrete type knowledge used.
The text was updated successfully, but these errors were encountered: