-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/compile: extra allocations in race mode #36516
Comments
cc @randall77 as I believe he is the only one who meaningfully touched the race detector this cycle |
Here's a somewhat simpler reproducer:
Additionally, apply this hack to package
WIthout
With
So the race detector makes sync.Pool less effective. Not really sure what's going on there, but it isn't this issue. This happens for both 1.13 and tip. With
So we're getting an extra 2 allocations per iteration.
For some reason, with |
So it isn't the
Somehow the compiler is deciding that the |
In
Probably want something more explicit than that, though. |
Re: sync.Pool being less effective with race mode enabled, that is intentional, to try to prevent the pool from hiding work that the race detector could catch bugs in. // Put adds x to the pool.
func (p *Pool) Put(x interface{}) {
if x == nil {
return
}
if race.Enabled {
if fastrand()%4 == 0 {
// Randomly drop x on floor.
return
} |
Change https://golang.org/cl/214679 mentions this issue: |
Change https://golang.org/cl/215477 mentions this issue: |
CL 214679 added a -race test which shouldn't be run when cgo is not enabled. Fixes the nocgo builder. Change-Id: Iceddf802c4ef6c0de2c3a968e86342303d2d27d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/215477 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
What version of Go are you using (
go version
)?go 1.14 beta1
Does this issue reproduce with the latest release?
no
What operating system and processor architecture are you using (
go env
)?GO111MODULE=""
GOARCH="amd64"
GOBIN="/Users/lni/gobin"
GOCACHE="/Users/lni/Library/Caches/go-build"
GOENV="/Users/lni/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/lni/go"
GOPRIVATE=""
GOPROXY="https://mirrors.aliyun.com/goproxy"
GOROOT="/usr/local/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/b5/ndb6rntd4ys0451zchd64p_m0000gn/T/go-build700408697=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Run the following test with and without -race
What did you expect to see?
The test should pass with or without -race on 1.14 beta1
What did you see instead?
On 1.14 beta 1, it fails when -race is enabled, it passes when -race is not enabled. On 1.13.x, it passes with or without -race.
The text was updated successfully, but these errors were encountered: