-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performance
Milestone
Description
What version of Go are you using (go version)?
$ go version 1.16.3
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env)?
go env Output
$ go env GO111MODULE="auto" GOARCH="amd64" GOBIN="" GOCACHE="/mnt/go-cache" GOENV="/mnt/ubuntu/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/mnt/jenkins/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/mnt/jenkins" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.16.3" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" 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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build4206356499=/tmp/go-build -gno-record-gcc-switches"
What did you do?
We are upgrading from Go 1.15.8 to Go 1.16.3 and found a noticeable benchmark regression. Here is a bit set setting i-th bit
package main
const remMask = uint64(1)<<6 - 1
type bitset struct {
b []uint64
}
func (b *bitset) set(i int) {
m := uint64(1) << (uint64(i) & remMask)
b.b[i>>6] |= m
}
func (b *bitset) unset(i int) {
m := uint64(1) << (uint64(i) & remMask)
b.b[i>>6] &^= m
}package main
import (
"math/rand"
"testing"
)
func BenchmarkSet(b *testing.B) {
const n = 10
const m = 1<<n - 1
const numWords = (1 << n + 63) >> 6
bs := &bitset{
b: make([]uint64, numWords),
}
r := rand.New(rand.NewSource(0))
bits := make([]bool, 1<<n)
for i := range bits {
bits[i] = r.Intn(2) == 1
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
if bits[i&m] {
bs.set(i & m)
} else {
bs.unset(i & m)
}
}
}Here is the benchmark result comparing 1.15.8 and 1.16.3.
goos: linux
goarch: amd64
cpu: Intel(R) Xeon(R) Platinum 8124M CPU @ 3.00GHz
Set-36 1.64ns ± 1% 2.89ns ± 1% +76.54% (p=0.001 n=7+7)
I bisected it, the benchmark regressions started at 96139f2
What did you expect to see?
Less performance regression.
What did you see instead?
+76.54% performance regression.
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performance