cmd/compile: reordering struct field accesses can alter performance #22479
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 operating system and processor architecture are you using (
go env
)?What did you do?
https://play.golang.org/p/d5g7tuaxHW
What did you expect to see?
Both of them performing equally.
What did you see instead?
With 6 runs of each on an idle machine:
This is a minifiedin version of a performance issue I had in a very hot function. In particular, the function is the ASCII fast path of a rune advance method.
Here's the assembly for the two funcs:
Funnily enough, the faster one results in an extra instruction. How that makes sense is beyond me. Perhaps it's because the first one accesses
8(AX)
three times, and the second only twice?My understanding of the compiler and assembly are limited, so any pointers welcome.
/cc @randall77 @philhofer
The text was updated successfully, but these errors were encountered: