More excellent work by the Go team!

304 views
Skip to first unread message

Robert Engels

unread,
Jun 21, 2024, 12:15:05 PM (9 days ago) Jun 21
to golang-nuts
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

Brian Candler

unread,
Jun 21, 2024, 3:11:02 PM (8 days ago) Jun 21
to golang-nuts
4775.994 ± 13310.309

Those are pretty wide error bars though...

Robert Engels

unread,
Jun 21, 2024, 3:15:27 PM (8 days ago) Jun 21
to Brian Candler, golang-nuts
Yep. Haven’t dig into it. I assume it has to do with allocations. That it is 2x faster than Go is somewhat suspect as well. 

I was more sharing for the change in Go performance. 

On Jun 21, 2024, at 2:11 PM, 'Brian Candler' via golang-nuts <golan...@googlegroups.com> wrote:

> 4775.994 ± 13310.309
--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/57b5e091-f309-4d5f-b102-f58c3d344776n%40googlegroups.com.

robert engels

unread,
Jun 22, 2024, 5:50:22 PM (7 days ago) Jun 22
to Brian Candler, golang-nuts
Thanks for point it out Brian. I must of had some background interference. I re-ran the tests, Go was the same, Java is

Benchmark                           Mode  Cnt     Score    Error  Units
TestJavaDispatch.TestArrayDispatch  avgt    9  4367.196 ± 50.227  ns/op
TestJavaDispatch.TestDispatch       avgt    9     0.942 ±  0.005  ns/op
TestJavaDispatch.TestIDispatch      avgt    9     1.341 ±  0.040  ns/op

So the error is much less.

Reply all
Reply to author
Forward
0 new messages