Bisecting Go performance degradation

Charles Darwin — just a nice first picture for a post and a hint for an impatient reader.
func BenchmarkWrite(b *testing.B) {
f, err := os.Create("/dev/null")
if err != nil {
panic(err)
}
defer f.Close()
buf := make([]byte, 512) b.ResetTimer()
for i := 0; i < b.N; i++ {
f.Write(buf)
}
b.StopTimer()
}
go get golang.org/dl/go1.11
go1.11 download
go get golang.org/dl/go1.12
go1.12 download
$ go1.11 test -test.run=XXX -bench=BenchmarkWrite -benchmem -memprofile mem.old -cpuprofile cpu.old | tee old.benchgoos: darwin
goarch: amd64
pkg: github.com/centrifugal/centrifuge
BenchmarkWrite-8 1000000 1167 ns/op 0 B/op 0 allocs/opPASS
ok github.com/centrifugal/centrifuge 1.201s
$ go1.12 test -test.run=XXX -bench=BenchmarkWrite -benchmem -memprofile mem.new -cpuprofile cpu.new | tee new.benchgoos: darwin
goarch: amd64
pkg: github.com/centrifugal/centrifuge
BenchmarkWrite-8 1000000 2184 ns/op 0 B/op 0 allocs/opPASS
ok github.com/centrifugal/centrifuge 2.226s
$ benchcmp old.bench new.benchbenchmark            old ns/op     new ns/op     delta
BenchmarkWrite-8 1167 2184 +87.15%
benchmark old allocs new allocs delta
BenchmarkWrite-8 0 0 +0.00%
benchmark old bytes new bytes delta
BenchmarkWrite-8 0 0 +0.00%
$ go tool pprof cpu.old
> web
$ go tool pprof cpu.new
> web
$ git rev-list --no-walk go1.11..go1.12 | wc -l
1684
git clone git@github.com:golang/go.git ~/go.dev
mkdir regression_search
benchmany -d regression_search -order metric -benchflags '-test.run=XXX -test.bench=BenchmarkWrite' -buildcmd='/Users/ayuemelin/go.dev/bin/go test -c' -C /Users/ayuemelin/go.dev/ go1.11..go1.12
commit 5e9ad4a, iteration 1/5: building...
commit 5e9ad4a, iteration 1/5: running...
commit 5e9ad4a, iteration 2/5: running...
commit 5e9ad4a, iteration 3/5: running...
commit 5e9ad4a, iteration 4/5: running...
commit 5e9ad4a, iteration 5/5: running...
commit ef21689, iteration 1/5: building...
45/360 runs, 63 unstarted+0 partial+9 done+0 failed commits, ETA 1h28m36s
  • You need to run your benchmarks on a main target system
  • You can run benchmark in your project automatically against different Go revisions using benchmany tool
  • You can bisect simply enough which commit caused regression in your Go code using benchmany -order metric
  • Sometimes a quick Twitter search can resolve the root cause of problem :)

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What are your programming weaknesses?

Orchestrating your first pipeline on Apache Airflow with LocalExecutor

Food for Agile Thought #189

Deploying Flutter with Github Actions

A Debugging Primer with CVE-2019–0708

What is Reliability

Unlock Modern Portal

Head in the Clouds: Microsoft Azure

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alexander Emelin

Alexander Emelin

Moscow

More from Medium

A good summary of Go lang basic syntax

Delve With VSCode To Debug Go App

TicTacGo — An Intro to Golang