Go Binary Sizes Have Been Pretty Stable
Update February 27th 2023: This was updated to include Go versions all the way up to 1.20
In 2013 I wrote an unintentionally inflammatory post: Go Binary Sizes Are Growing out of Control. I had imagined no one would read it, but it took off. I wrote it because I noticed my binaries getting larger as I upgraded versions of Go and found it curious.
Much has changed since then; biggest of all there have a handful of major releases of Go in that time.
I wanted to find out how much this had changed since my post went up. I used Docker to automate the process of compiling against major releases of Go. The exact code I used is on GitHub.
I hit a couple of hurdles. The oldest official version of Go on Docker Hub is 1.2 - which happens to be the version my previous post left off. Also, many of the programs from the previous comparison no longer compile in such old versions of Go.
Thus, consider this a standalone comparison rather 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
- hello world using println
- Hookah - a tool for GitHub automation
- imgavg - a tool for averaging a collection of images
- sqlread - a tool for querying MySQL dumps without loading them into a database.
Without further ado, the raw data in megabytes.
The trendlines show the majority of the projects have a small downtick in size. The Go 1.5 and Go 1.6 releases caused a pretty universal uptick which 1.7 seems to have largely mitigated.
Hookah shows by far the most fluctuation in size by a pretty large margin. This is interesting because comparing dependencies the only builtin packages Hookah uses that sqlread does not are
sqlread itself actually utilizes a pretty large number more. This could indicates the variation is deeper than the changes to the built in libraries, and potentially more to do with the compilation output and optimization.
Everything except for the simplest "Hello World"
hello-nofmt has shown an overall decrease.
hello-nofmt boils down to
println("Hello, 世界") has shown an overall 658kb increase. This is likely the purest illustratration the growth in size of the runtime.
Go binaries are not "growing out of control". They're pretty stable and for the most part have shown a decrease.
I'm still hopeful future optimizations will help improve sizes. Given WASM becoming a major compilation target, size matters more than ever as it directly affect load times.