I had the opportunity to revisit my interface dispatch benchmark (
https://github.com/robaho/go-dispatch-test).
Previously, the dispatching using pointer receivers was nearly 3x slower (i.e. 5.5 ns to 12.6 ns):
goos: darwin
goarch: amd64
BenchmarkIDispatch-8 300000000 5.56 ns/op
BenchmarkDispatch-8 2000000000 1.57 ns/op
BenchmarkArrayParms-8 200000 9265 ns/op
PASS
and
goos: darwin
goarch: amd64
BenchmarkIDispatch-8 100000000 12.6 ns/op
BenchmarkDispatch-8 2000000000 1.57 ns/op
PASS
With the latest Go 1.22.4, the performance difference has reversed ! (tests have been combined for simplicity).
goos: darwin
goarch: amd64
cpu: Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
BenchmarkIDispatch-8 535263746 2.118 ns/op
BenchmarkIDispatchPtr-8 675721244 1.773 ns/op
BenchmarkDispatch-8 1000000000 0.6953 ns/op
BenchmarkArrayParms-8 184212 6440 ns/op
PASS
Pretty impressive work. The interface based dispatch is almost equal to the Java version now:
Benchmark Mode Cnt Score Error Units
TestJavaDispatch.TestArrayDispatch avgt 3 4775.994 ± 13310.309 ns/op
TestJavaDispatch.TestDispatch avgt 3 0.941 ± 0.088 ns/op
TestJavaDispatch.TestIDispatch avgt 3 1.331 ± 0.146 ns/op