cmd/compile: global vars initialized with func calls like net.IPv4 allocate at init time #51773
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
See https://go-review.googlesource.com/c/go/+/391114, which replaces lines like:
with:
The latter is certainly more verbose, which is the reason why the CL isn't submitted, but the former does allocate at init time as reported by
GODEBUG=inittrace=1
. Below are three samples before and after the 7 var changes:The funcs in question are tiny, and they allocate fixed-size slices. As far as I can tell, they are getting inlined. I imagine it should be possible for the compiler to avoid the allocations even with the function calls.
cc @randall77 @josharian
The text was updated successfully, but these errors were encountered: