You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ go version
go version go1.18beta2 linux/amd64
$ go test -bench=.
goos: linux
goarch: amd64
pkg: example.com
cpu: Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
Benchmark_Sum_RangeSliceIdx_Inline-4 1996579 603.2 ns/op
Benchmark_Sum_RangeSliceIdx_NoInline-4 2176748 545.0 ns/op
$ go version
go version go1.17.6 linux/amd64
$ go test -bench=.
...
Benchmark_Sum_RangeSliceIdx_Inline-4 2201970 534.3 ns/op
Benchmark_Sum_RangeSliceIdx_NoInline-4 2250338 535.2 ns/op
There's a nop pad to align the cmp/jlt to fix #35881. That could conceivably be the reason for the slowdown, in which case the performance difference is just because we got alignment-lucky in the noninline case and alignment-unlucky in the inline case.
It could also conceivably be the larger instruction / additional microop required for the load. The noninline case effectively lifts the computation of &a out of the loop.
The first one seems like there's nothing to fix, except possibly to revert the #35881 fix some day. (If I revert it on my desktop right now, the performance goes down by a factor of 2! So not today.)
The second one would need some sort of partial lifting out of the loop. That's #15808, with the additional complication here that we'd have to break a single instruction into 2 parts and lift just one of those parts out of the loop.
So I don't think there's anything to do for this issue. I'm going to close in favor of #15808.
(This doesn't reproduce for 1.17 because we don't inline functions with loops in 1.17.)
Activity
randall77 commentedon Feb 5, 2022
Inner loop in the noninlined case:
In the inlined case:
There's a nop pad to align the cmp/jlt to fix #35881. That could conceivably be the reason for the slowdown, in which case the performance difference is just because we got alignment-lucky in the noninline case and alignment-unlucky in the inline case.
It could also conceivably be the larger instruction / additional microop required for the load. The noninline case effectively lifts the computation of
&aout of the loop.The first one seems like there's nothing to fix, except possibly to revert the #35881 fix some day. (If I revert it on my desktop right now, the performance goes down by a factor of 2! So not today.)
The second one would need some sort of partial lifting out of the loop. That's #15808, with the additional complication here that we'd have to break a single instruction into 2 parts and lift just one of those parts out of the loop.
So I don't think there's anything to do for this issue. I'm going to close in favor of #15808.
(This doesn't reproduce for 1.17 because we don't inline functions with loops in 1.17.)