Skip to content

runtime: with -test.blockprofile program run even faster. #57319

@zdyj3170101136

Description

@zdyj3170101136

What version of Go are you using (go version)?

$ go version
go version go1.19.3 linux/amd64

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=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/go/pkg/mod/"
GONOPROXY=""
GONOSUMDB="gopkg.mihoyo.com"
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/root/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/profilerbench/go.mod"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build799047141=/tmp/go-build -gno-record-gcc-switches"GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/go/pkg/mod/"
GONOPROXY=""
GONOSUMDB="gopkg.mihoyo.com"
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/root/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/profilerbench/go.mod"
GOWORK=""
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 -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build799047141=/tmp/go-build -gno-record-gcc-switches"

What did you do?

run benchmark test of src/runtime/chan_test.go.
one with blockprofile, another not.

/root/go/bin/go test -run=^$ -bench=BenchmarkChanProdConsWork0$ -benchtime=10000000x
goos: linux
goarch: amd64
pkg: github.com/zdyj3170101136/profilerbench/sync
cpu: Intel(R) Xeon(R) Platinum 8269CY CPU @ 2.50GHz
BenchmarkChanProdConsWork0-8    10000000               839.0 ns/op
PASS
ok      github.com/zdyj3170101136/profilerbench/sync    8.490s

/root/go/bin/go test -run=^$ -bench=BenchmarkChanProdConsWork0$ -benchtime=10000000x -blockprofile=b
goos: linux
goarch: amd64
pkg: github.com/zdyj3170101136/profilerbench/sync
cpu: Intel(R) Xeon(R) Platinum 8269CY CPU @ 2.50GHz
BenchmarkChanProdConsWork0-8    10000000               793.7 ns/op
PASS
ok      github.com/zdyj3170101136/profilerbench/sync    8.059s

What did you expect to see?

with blockprofile, the program should run slower!

What did you see instead?

with blockprofile, the program run faster !

helpful information

here is the cpu profile diff:
截屏2022-12-15 下午3 23 00

  • saveblockevent cost lots of cpu.
  • runtime.lock save lots of cpu, which means contention is less.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions