Space Cat, Prince Among Thieves

Go Binary Sizes Are Relatively Stable

Almost six years ago I wrote an unintentionally inflammatory post I'd wrongly imagined no one would read: Go Binary Sizes Are Growing out of Control. I had noticed my binaries getting larger and larger as I upgraded versions of Go and wanted to express my frustration.

Much has changed since then; there have been ten major releases of Go in that time.

I was curious how much this had changed since my post went out. I realized I could use Docker to easily automate the process of compiling against all the major releases of Go. The exact code I used is on GitHub.

I hit a couple of hurdles. First, the oldest official version of Go on Docker Hub is 1.2 - which happens to be the version my previous post left off. Secondly, a number of the programs I'd previously compared no longer compiled in such old versions of Go.

As I didn't want to bother sifting through old versions of projects or manually dealing with old versions of Go I decided to make this more of a standalone comparison than a direct continuation of the previous post.

I ended up going through most of my Go projects to find what would actually compile in ancient versions of Go.

The tools I compiled for the comparison are in order hello world using fmt, hello world using println, Hookah - a tool for GitHub automation, imgavg - a tool for averaging a collection of images, and sqlread - a tool for querying MySQL dumps without loading them into a database.

The Results

Without further ado, the raw data in megabytes.

binary1.21.31.41.51.61.71.81.91.101.111.12
hello2.2401.8241.9412.3672.2881.6341.5521.8602.0121.9071.997
hello-nofmt0.5770.4750.6351.0761.1011.0030.9601.0351.0861.0681.127
hookah8.3626.7496.8807.6928.7476.3966.5586.8107.3207.2868.239
imgavg3.7242.9973.0423.5643.5122.7062.5082.6262.8162.7322.848
sqlread4.8783.7483.8374.3494.2323.1843.0573.1093.3063.1503.304

 

Chart of Binary Sizes

You can see from the trendlines that for the majority of the projects there has been a small downtick in size overall. The 1.5 and 1.6 releases causing a pretty universal uptick which 1.7 seems to have quickly mitigated.

Curiously Hookah shows by far the most fluctuation in size by a pretty large margin. This is increasingly curious because comparing recursive dependencies the only builtin packages Hookah uses that sqlread does not are regexp and regexp/syntax, whereas sqlread itself actually utilizes a pretty large number more. This to me indicates it's variation is probably deeper than just changes to the built in libraries but more to do with the compilation output and optimization itself.

Everything except for the simplest Hello World "hello-nofmt" has shown an overall decrease. On the other hand hello-nofmt which boils down to println("Hello, 世界") plus boilerplate has shown an overall 550kb increase. This clearly illustrates the flucution and growth in size of the compiled runtime.

Conclusion

Go binaries are not "growing out of control". They're pretty stable overall and for the most part have shown a decrease.

All said and done however they are still larger than I would like. I'm hopeful things like tree shaking will help improve this in the future. There is certainly cause for hope with WASM becoming a major compilation target size will matter more than ever as it will directly affect load times.


Read More / Comment »

Recent Comments

You use floor(sqrt(r^2-floor(x)^2))? r=radius (weight=r×2)
Link

I found this page Googling a similar problem for Nokogiri so I thought I would share another hard-won lesson on macOS gembuilding. On macOS Catalina, while t…
Link

Wait, speaking of building, what if we just use "wooden axe" plugin? I think that is much easier to achieve what we want...BTW, I use this generator for my stic…
Link

removing and reinstalling the CLT solved the issue...
Link

When using sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target / -allowUntrusted i get the erro…
Link