cmd/compile/internal/amd64: huge performance degradation (register allocation issue?) #50821
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.
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
)?go env
OutputWhat did you do?
I have wrote a function which I guess stresses the register allocation in the Go compiler.
The problem I (accidentally) discovered is that swapping two independent lines in the source code causes spillage of the variables from the registers into the stack. This reduces performance of my benchmark by 30%!
Excerpt from the "fast" code version:
Excerpt from the "slow" code version:
As you can see the lines are independent and the compiler is free to reorder the code.
I have a self-contained 150 line source file ready for
go test -bench
which reproduces this issue. I can share this file with the compiler developers privately for the purpose of the issue reproduction only due to the code being proprietary. Please advise on how to proceed.What did you expect to see?
I expect to see both versions compiled into the same binary code with the same performance.
What did you see instead?
Function asm code change from
STEXT nosplit size=1158 args=0x68 locals=0x40 funcid=0x0
toSTEXT size=1355 args=0x68 locals=0x78 funcid=0x0
. Performance drop of ~30% from 2618 ns/op to 3905 ns/op.The text was updated successfully, but these errors were encountered: