-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: possible missed optimization in append benchmark #25916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Please run the benchmarks with -count=20 -cpu=1 on a quiet system (no network or browser) and pipe the output to a file then use https://godoc.org/golang.org/x/perf/cmd/benchstat to compare the results to remove some problems with outliers. I see some variance (between var bug = false vs true) from run to rune and some sub ns differences which is not unusual even on a quiet system:
|
Sorry but currently I can't shutdown the network and the browser.
During the weekend I will try to run again the benchmark after a system reboot. |
The output does not show a comparison between false and true and no multiple runs. I used with go tip (to be 1.11 in the future):
Doesnt show any significant or unusual difference between variable values. |
Sorry, I have never used benchstat before; the data I posted was from benchstat append.true. Here is the correct data:
I will try to use go tip during the weekend. |
Thanks is that with bug as const or var? |
With const. |
Ok. I see a speed up with const bug set to true too but not for changing bug between true and false with bug as a var. That said the loop alignment/code layout is not unexpectedly different for bug const true vs false (as the compiler can optimize some code away) which can lead to performance differences. If so i would not count this as a bug (unless the outcome is wrong) but an opportunity to investigate and change the compiler to generate better code for the const bug is true case. Removing the "if" block below (and thereby changing the code layout) makes the benchmark a lot slower on my system:
|
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.10.3 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN="/home/manlio/.local/bin"
GOCACHE="/home/manlio/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/manlio/.local/lib/go:/home/manlio/code/src/go"
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build931873105=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I wrote a simple benchmark to check the performance of append versus copy.
The benchmark is here:
https://play.golang.org/p/jA7Fb0oON6Z
The benchmark result is:
The unexpected result is when bug is set to true. In this case the benchmarks results are:
The same result is produced when I change bug from a const to a var, even if it is set to false.
When I set GOARCH=386 with bug=true, the benchmark result is:
This seems to be an issue with the amd64 compiler.
This is the assembly listing when bug is false:
https://pastebin.com/kDVTypHF
and this is the assembly listing when bug is true
https://pastebin.com/VErtqZw6
This is the discussion of golang-nuts:
https://groups.google.com/forum/#!topic/golang-nuts/lJvBonZg62g
What did you expect to see?
The benchmark result should be the same, with bug set to false or bug set to true.
What did you see instead?
When bug is set to true, the Append benchmark is faster than the Copy benchmark.
The text was updated successfully, but these errors were encountered: