cmd/compile: avoid unnecessary allocations for consecutive appends #44628
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
go1.16
The following function will often incur two allocations, one for each
append
call.However the compiler could potentially know the length of the extra data in advance
(len(f) + 4) and hence allocate at most once.
Working around this is awkward because to do that properly requires duplication of the
append
capacity-growing algorithm so that the slice will grow by a multiplicative rather than a constant factor. When generics arrive, I'd love to see a function like this in the standard library (that would be useful for #14325 amongst others), but the above optimization would still be useful to avoid using that.Related issues:
The text was updated successfully, but these errors were encountered: