Closed
Description
Go version
go version go1.22.8 darwin/amd64
Output of go env
in your module/workspace:
n/a
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.
package main
func New(x string) *string {
return &x
}
var s *string
func main() {
s = New("abc")
}
$ go build main.go && wc -c main
1371632 main
package main
func New[T any](x T) *T {
return &x
}
var s *string
func main() {
s = New("abc")
}
$ go build main.go && wc -c main
1371664 main
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.
Metadata
Metadata
Assignees
Labels
No labels