Go’s best friend: UPX, the executable compressor

Image for post
Image for post
The efficient dream team

When you start to develop with Go (a.k.a. Golang), one thing you realize is that the generated executable is “big”. A simple HTTP “Hello world” app has a size around 7 MB (depends on the OS and architecture).

For many cases is not a problem, but if you need to transfer it through Internet or to store it in an embedded device… it’s not good.

Introducing UPX

The Ultimate Packer for eXecutables, UPX, is an executable compressor with very fast decompression time for many of architecture-OS combinations.

The most important architectures are supported: i386, x86_64, arm64, armeb, powerpc, etc.

Regarding OSs, Windows, Linux, BSD and even DOS are supported too.

It’s very easy to install and to use.

In Mac OS X

brew install upx

In Ubuntu

sudo apt install upx

Deflating our Go app

We use this HTTP Server example in go.

Now we build our app (Mac OS X Catalina with Go 1.14)

go build -o simple-http-server

The size in bytes is: 7.364.228, around 7 MB.

Time to compress it with upx

upx simple-http-server

The magic starts

Image for post
Image for post
The UPX show!

The resulting executable is around the half size of the original!

Its execution is very fast too.

As you can see it has no complexity. You no longer have any excuses to compress your executables with UPX.

Please, if you liked it, give it a round of applause. And if you want to know more about DevOps, Kubernetes, Docker, etc … follow me :) KR

Image for post
Image for post

Written by

CTO @ Digitalilusion.com & DigitalSecured.net Beyond-Full-stack developer #go #python #kubernetes

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store