Shrink Go binaries 7x with this one weird trick
blog.filippo.io
blog.filippo.io
I started developing a system from home and when deploying to a VPS for testing and production. Transferring Go binaries was like waiting for a floppy disk to copy due to poor Internet infrastructure. Compression didn't help much.
It turned out to be significantly faster to push to a remote git and have a hook do the build. I think before you look to compress a go binary consider if there aren't other options.
Thank goodness for multipart uploads, at least.
This gives me the ability to `rsync` them up rather than copy, using its ability to only transfer the pieces of the files that have changed.
We have a ~20MB .war file that I have done this with over airport wifi, and it ended up only transfer a few 10's of KB (maybe 100) between compiles.
I guess I should be thankful I mainly work with text and not images, video or large proprietary file formats otherwise I think I would be out of the game.
My phone is now about 5 times faster than my home Internet for both uploads and downloads but also significantly more variable and expensive. The fibre internet upgrade that was scheduled for last year had the technology downgraded and the rollout delayed due to politics.
I've been throwing around an idea for a site called "Church of the Byte Savers" or some other silly name based around saving hard drive space and bandwidth. e.g. Dropbox is good because it has LAN sync, whereas OneDrive will send your data around the world just to get it to a second PC on your network.
I like that. I see people preaching how we've become accustomed to large drive space and fast internet and we're just wasting it all out of laziness.
Kind of like the post Muad'dib Fremen that got soft on water discipline.
rsync --inplace -vaz sourcefile user@remote:/targetdir/It got much less fun when each deploy to the prod server took an hour to complete.
Depends what that 30MB does, or how much of it is actually needed - it's less of a problem if all those bytes are used in some form or another, than if a significant portion of them are "dead code" that is never used and only serves to take up space in memory, on disk, and in communications channels whenever it's transferred somewhere.
and I would not trade (build time | complexity | performance | debug-ability) for it
On the contrary, smaller binaries are usually going to be better at all of those, except perhaps "debug-ability" if you keep the debugging symbols in the same file.
> Depends what that 30MB does, or how much of it is actually needed [....]
Moreover, let's consider a CLI tool suite. Dozen little tools, each doing perfectly what it was designed to (think of coreutils, util-linux, sysstat, binutils, or iproute2). Such a suite suddenly weighs 300MB, more than X.Org or PostgreSQL (or the two combined). Does it really do more than any of these two to justify the size? I doubt it.
On the other hand, internet speeds have not increased quite as dramatically, so we can still relate with stories of "this app is how big? And it only does what?"
301 kB.
I noticed this recently when trying to upload a container image that happened to include Terraform.
- the startup time increases
- if you run several instances of an app, they consume more memory because code uses anon mapping instead of file mapping
- the whole executable file is loaded to memory at startup
That bug is 3 years old and seems to be architecture-specific.
The "fix" is that the Debian team stopped stripping the binaries ;).
[0] https://groups.google.com/d/msg/golang-dev/ABppMOjYP6w/6JsfT... [1] https://github.com/docker/docker/blob/2a95488f7843a773de2b54...
If you expand your context from "day and age" to "country, bandwidth provider and pricing" you might start believing the problem a bit more
Well, binary size is pretty important for embedded work. Or mobile work.
> Ok, I lied, there's no weird trick. However, you can easily reduce a Go binary size by more than 6 times with some flags and common tools.
This isn't belittling operations folks, this is more of a comment on how complicated, complex, and obfuscated modern browsers are.
I should update the post as the binaries come out especially larger in the new versions of Go written in Go. I believe Hello Worldis up to at least 3mb.
Am I way, way off base? Should I perhaps retake high school?
Edit: the smaller number is assumed 1x. Got it. Still feels weird.
You also see it with slower; "the unoptimized code is 2x slower". Huh? Do you mean "takes 2x the time"?
I cringe every time.
This is the (IMO circular) assertion that is made by fiat. If you believe this, then you believe it.
I get the meaning, it just isn't logical to me. To use the 'x' or '*' as multiplication should mean that many repetitions of something, not the reciprocal of that number.
Reasonable people disagree.
Let's maybe spend a couple extra minutes coming up with less link-baity titles.