I stumbled across a performance regression on ARM64 for go 1.18.6 and 1.19.1 that wasn't present in earlier releases. In the following benchmark, you can see `BenchmarkSliceOfArray` experiences a 70% increase in
execution time while `BenchmarkSliceOfInt` remains unchanged.
BenchmarkSliceOfArray 413121 2855 ns/op
BenchmarkSliceOfArray 216478 4881 ns/op
Through the use of `pprof` and `GOSSAFUNC go build`, it was observed that the latest release employs `runtime.memmove` and accounts for the change in performance. I don't see the invocation of `memmove` or the perfromance degradation on AMD64.
I believe this can be traced back to - https://go-review.googlesource.com/c/go/+/425234.
Is this new behavior in this scenario correct or unindented?
Should I open an issue for this?
I am a newbie, so forgive me if there are errors in my approach.
----
go version go1.19 darwin/arm64
% GOMAXPROCS=1 go1.19 test -cpuprofile cpu.prof -bench .
goos: darwin
goarch: arm64
pkg: foo/bar
BenchmarkSliceOfInt 572226 2066 ns/op
BenchmarkSliceOfArray 413121 2855 ns/op
PASS
ok foo/bar 3.488s
----
go version go1.19.1 darwin/arm64
% GOMAXPROCS=1 go test -cpuprofile cpu.prof -bench .
goos: darwin
goarch: arm64
pkg: foo/bar
BenchmarkSliceOfInt 527084 2065 ns/op
BenchmarkSliceOfArray 216478 4881 ns/op
PASS
ok foo/bar 2.468s
ok foo/bar 3.538s
----
package datamove
type Array [2]int
func moveSliceOfArrayData(s []Array) []Array {
for i := 1; i < len(s); i++ {
s[i-1], s[i] = s[i], s[i-1]
}
return s
}
func moveSliceOfIntData(s []int) []int {
for i := 1; i < len(s); i++ {
s[i-1], s[i] = s[i], s[i-1]
}
return s
}
----
package datamove
import (
"testing"
)
var resultInt []int
var resultArray []Array
func BenchmarkSliceOfInt(b *testing.B) {
var r []int
for n := 0; n < b.N; n++ {
s := make([]int, 1000)
r = moveSliceOfIntData(s)
}
resultInt = r
}
func BenchmarkSliceOfArray(b *testing.B) {
var r []Array
for n := 0; n < b.N; n++ {
s := make([]Array, 1000)
r = moveSliceOfArrayData(s)
}
resultArray = r
}
I am unable to reproduce your results on AMD64. I don't see any regression.