I am unable to reproduce your results on AMD64. I don't see any regression.
Run your benchmarks with option -benchmem. Version: devel go1.20-1eeb257b88 Tue Sep 20 02:58:09 2022 +0000 Sizeof(Array{}): 16 Sizeof(int(0)): 8 goarch: amd64 BenchmarkSliceOfInt-4 391646 2583 ns/op 8192 B/op 1 allocs/op BenchmarkSliceOfArray-4 236977 4869 ns/op 16384 B/op 1 allocs/op Version: go1.17.13 Sizeof(Array{}): 16 Sizeof(int(0)): 8 goarch: amd64 BenchmarkSliceOfInt-4 426343 2383 ns/op 8192 B/op 1 allocs/op BenchmarkSliceOfArray-4 233817 4771 ns/op 16384 B/op 1 allocs/op The difference is type int is 8 bytes and type [2]int (type Array) is 16 bytes. Change the type of Array to 8 bytes (type [1]int). Version: devel go1.20-1eeb257b88 Tue Sep 20 02:58:09 2022 +0000 Sizeof(Array{}): 8 Sizeof(int(0)): 8 goarch: amd64 BenchmarkSliceOfInt-4 405793 2562 ns/op 8192 B/op 1 allocs/op BenchmarkSliceOfArray-4 469999 2540 ns/op 8192 B/op 1 allocs/op Version: go1.17.13 Sizeof(Array{}): 8 Sizeof(int(0)): 8 goarch: amd64 BenchmarkSliceOfInt-4 440340 2378 ns/op 8192 B/op 1 allocs/op BenchmarkSliceOfArray-4 481071 2400 ns/op 8192 B/op 1 allocs/op There is no significant difference. peter On Monday, September 19, 2022 at 10:01:37 PM UTC-4 jpsw...@gmail.com wrote: > 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 > > } > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/73f49ef0-5e4e-4bb8-9976-534894ffde38n%40googlegroups.com.