-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: binary size increase from generics #70045
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
do you have a self contained reproducer? |
The repo is open source but a bit complex. Synthetic example yields additional 400 bytes, not sure that's relevant? package main
import _ "github.com/samber/lo"
type element struct {
value string
}
func (c *element) Value() string {
return c.value
}
func main() {
var list []element
// 2953986 bytes
res := make([]string, 0, len(list))
for _, el := range list {
res = append(res, el.Value())
}
// 2954306 bytes
// res := lo.Map(list, func(el element, _ int) string {
// return el.Value()
// })
_ = res
} Could I produce any kind of export data that might be helpful? |
Another attempt (replacing main.go of https://github.com/evcc-io/evcc): package main
import (
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util/config"
"github.com/samber/lo"
)
type vehicles struct{}
// 9960802 bytes
// func (vv *vehicles) Instances() []api.Vehicle {
// devs := config.Vehicles().Devices()
// res := make([]api.Vehicle, 0, len(devs))
// for _, dev := range devs {
// res = append(res, dev.Instance())
// }
// return res
// }
// 9961538 bytes
func (vv *vehicles) Instances() []api.Vehicle {
return lo.Map(config.Vehicles().Devices(), func(dev config.Device[api.Vehicle], _ int) api.Vehicle {
return dev.Instance()
})
}
func main() {
var vv vehicles
_ = vv.Instances()
} Again only a 700 bytes difference. |
looks like you have something other than generics that's increasing your binary size Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only. For questions please refer to https://github.com/golang/go/wiki/Questions |
Appreciate the feedback. If you want to take the time- any idea what could increase binary size when only this single function is being updated? Is there any AST or similar of the compiled program that I could export for inspection? Thank you! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Replace
for
loop with generic function.Before:
After:
with
lo.Map
simply being (samber/lo):What did you expect to see?
Similar or smaller binary size
What did you see instead?
Binary size increased by 14kib for a single function call.
Before:
After:
The text was updated successfully, but these errors were encountered: