go: runtime: CL 501976 performance and jitter regression

Go version

go version go1.22.0 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/steve/.cache/go-build'
GOENV='/home/steve/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/steve/Go/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/steve/Go/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/steve/Go/go1.22.0/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/home/steve/Go/go1.22.0/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.22.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build502182501=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I am comparing the performance my project when compiled with Go 1.22.0 and when compiled with Go 1.21.7

The full instructions for my testing procedure and the result CPU profiles and the test program have been placed in a specially created Github repository

What did you see happen?

The performance of my project has dropped significantly with v1.22.0. Using the metric of performance used in my project, the performance with Go v1.21.7 is 146.28fps and the performance with Go v1.22.0 is 133.48fps. This is a drop of 8.75%

What did you expect to see?

I expected either no significant change or an increased performance rating. This method of measurement has been used for many years and has shown increases in performance as expected when new Go versions have been released. For example, the introduction of profile-guided optimisation, showed the expected increase in performance.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 42 (17 by maintainers)

Most upvoted comments

Thanks for the traces. Here are what 5s regions from each look like.

Without https://go.dev/cl/501976: image

With https://go.dev/cl/501976: image

In the first case, we can see that work tended to stay on the same thread for almost exactly 1s at a time (I’m actually not sure why it is quite so consistent). Afterwards, it is much less consistent, and the average time to stay in one place is noticeably lower.

These migrations are described in #65694. Gosched puts the G on the global run queue, so it makes sense that it is more likely to move to a different P/M after Gosched. An explicit wakep in Gosched will ensure that there is another M awake, which will be racing to run the G.

This is particularly unfortunate in your case, since there are idle Ps and thus there is no need to preempt at all. Last year, @felixge proposed https://go.dev/cl/460541 to avoid unnecessary preemption when there are idle Ps. If you can apply that CL (might not apply cleanly anymore), I’d be curious to hear the impact. I suspect it would eliminate you jitter and regression.

@qiulaidongfeng Nice! I didn’t know about benchstat. These are my results

     │ benchstat_1.27.1_maxgoproc_n.txt │ benchstat_1.22.0_maxgoproc_n.txt  │
     │              fps/op              │   fps/op    vs base               │
Test                         145.9 ± 1%   139.0 ± 1%  -4.77% (p=0.000 n=62)

So, at first flush it looks like the variation is more pronounced with a less powerful CPU

And when GOMAXPROC is set to 1 (on the same hardware)

     │ benchstat_1.27.1_maxgoproc_1.txt │ benchstat_1.22.0_maxgoproc_1.txt  │
     │              fps/op              │   fps/op    vs base               │
Test                         146.0 ± 0%   144.6 ± 0%  -0.96% (p=0.000 n=62)

https://github.com/JetSetIlly/gopher2600_performance_profile 404s, is it private ?

No. I missed the s off the end when I was copying and pasting. Doh! https://github.com/JetSetIlly/gopher2600_performance_profiles

@JetSetIlly since you already have everything setup can you benchmark GOEXPERIMENT=loopvar with go1.21.7 please ?