Skip to content
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

testing: b.Loop prevents range func inlining which drastically changes performance result #73166

Closed
mpx opened this issue Apr 4, 2025 · 4 comments
Labels
BugReport Issues describing a possible bug in the Go implementation.

Comments

@mpx
Copy link
Contributor

mpx commented Apr 4, 2025

Go version

go version devel go1.25-5eaeb7b455 Thu Apr 3 15:36:36 2025 -0700 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE='on'
GOAMD64='v1'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1699666494=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/tmp/bench-loop-rangefunc/go.mod'
GOMODCACHE='/home/user/golang/pkg/mod'
GOOS='linux'
GOPATH='/home/user/golang'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org'
GOROOT='/home/user/go-dev'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='local'
GOTOOLDIR='/home/user/go-dev/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='devel go1.25-5eaeb7b455 Thu Apr 3 15:36:36 2025 -0700'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Convert an old style benchmark loop containing a range-func loop to the new B.Loop construct.

Example benchmark: https://go.dev/play/p/TMQqkLTVnxB

What did you see happen?

goos: linux
goarch: amd64
pkg: bench
cpu: Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
BenchmarkIterRangeFunc-8   	307616280	         3.897 ns/op
BenchmarkLoopRangeFunc-8   	13051561	        96.68 ns/op
PASS
ok  	bench	2.861s

What did you expect to see?

The timing result should be roughly similar for both benchmarks, but instead there is a fairly severe performance reduction with B.Loop (25x).

This appears to be a good example of something to fix so B.Loop is more reliable and useful as per #73137 (comment).

@mpx
Copy link
Contributor Author

mpx commented Apr 4, 2025

Cc @aclements

@prattmic
Copy link
Member

prattmic commented Apr 4, 2025

cc @JunyangShao @dr2chase @golang/runtime

@aclements
Copy link
Member

Thanks. This is a good example of the problem in #73137. Let's track the work in that issue.

@gabyhelp gabyhelp added the BugReport Issues describing a possible bug in the Go implementation. label Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BugReport Issues describing a possible bug in the Go implementation.
Projects
None yet
Development

No branches or pull requests

4 participants