cmd/compile: range loop with large element has a significant cost #59706
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
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
Here's a benchmark of two approaches of writing
slices.Index
:Results:
I would have expected the results to be approximately the same, however, there's a significant cost to using
for i, v := range s
loop.As far as I was able to tell, the slower implementation ends up making more copies of the v.
I made a quick fix for slices package for the time being https://go-review.googlesource.com/c/go/+/486235.
The text was updated successfully, but these errors were encountered: