My Go patch got accepted the other day! Writing with encoding/binary is 1.5x faster for unsigned integers:
I described the original issue in “Hacker School Day 23-24: Waiting to Submit a Patch to Go“. I also yapped about it on my Twitter account already, so this post is mostly a little rehash and story telling. I won’t cover how I found it, but that’s explained in the blog post I linked above.
It took a while
I originally submitted the change on November 6th, and the changes were committed on December 22nd. A month and a half is a long time, but my experience is an outlier:
- When I submitted the change, Go was frozen for the release of 1.4
- Go transitioned from Mercurial to Git.
But things got faster
I ran the benchmarks that come with the encoding/binary package, then used the benchcmp tool to compare:
benchmark old MB/s new MB/s speedup BenchmarkReadInts 22.14 21.52 0.97x BenchmarkWriteInts 9.61 14.54 1.51x
Write speed exploded! I expected both read and write performance to improve though. I was also worried when I saw the minor negative speedup in read, so I wrote a silly script to run the benchmarks a few times in a row to help smooth out any background noise, and they averaged out the same.
So why aren’t reads faster?
Read takes a pointer, so it was hitting the fast path before. I got too excited when I submitted my patch and said “intDataSize ignores unsigned integers, forcing reads/writes to miss the fast path.” This only causes writes to get faster. Next time I should be less jumpy! Especially now that I know contributing to a big project isn’t the scary nightmare I thought it would be.
It was pretty cool to get to interact with Brad Fitzpatrick, Ian Lance Taylor, and Russ Cox over the course of the patch, even if those interactions can be summed up as:
- “not yet”
- “still not yet”
- “LGTM” 🙂
The takeaway for me is that it’s way less intimidating to send changes to a big project than I thought!