cmd/compile: long function names due to generic instantiation with large struct types #65030
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
Go version
go version devel go1.22-b702e0438a Mon Jan 8 20:15:52 2024 +0000 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Build this program:
https://go.dev/play/p/6Jsq0rUhQ9K
Source:
and examine the assembly (gcflags=-S).
What did you see happen?
At the call to slices.Insert in main function, here is an assembly fragment (from "go build -gcflags=-S -trimpath main.go"):
The program works properly, but note the name for the instantiated version of
slices.Insert
, which is almost 600 characters long. Of particular concern is that although the generic function is instantiated with the typeexec.Cmd
, the function name looks like it refers to an anonymous struct type that has all the fields ofcmd.Exec
, but in which all the field names/types are spelled out (including package paths, etc).In this example, the long function name is not that big a deal, but creates needless binary bloat, and for profilers (ex: pprof) and other tools that capture data files based on function names, the long names can result in much bigger data files.
More importantly however if you have a package with very long paths, and you import a large struct type from that package and instantiate a generic based on that, you can get absurdly long function names.
What did you expect to see?
Ideally it would be better to have generic functions names that are proportional in size to the length of their qualified type parameters (e.g. "os/exec.Cmd") as opposed to O(N * P) where N is the number of struct fields in the type param and P is the length of the import path of the type's package.
The text was updated successfully, but these errors were encountered: