Creating Small Go-Lang Executables
In the past couple of months I have be working on some projects and I found lots of things about GoLang that you might not know. One of them is creating small Executables.
Creating Small Executables
When I was creating FileCrypt, I tried to make it as small as possible. But what ever I tried I couldn’t get the executable size under 10MB. After some research I found out that when building your GO application with -ldflags “-s -w”. My executable size went from 10MB to 2MB, which is almost 20% decrease in size.
These flags remove debug information from the executable as a result makes it harder to debug your application.
But there are some reports that executables built using this flags have bugs see here. My recommendation is to distribute a stripped version of your application and a normal one.
If you want to decrease your executable size more you can , which is a executable packer this packed executable is sometimes detected by antiviruses. As I said in the above paragraph, you should distribute a normal executable with the Packed executable.
Unlike the GoLang build flags packing your executable with UPX has a performance impact which isn’t noticeable on new computers but it is on old one. It takes some time to run the executable when packed due to the fact that UPX has to decompress the executable packed inside it.