cmd/compile: code generated by generics seems inefficient #64699
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
generics
Issue is related to generics
Performance
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: