Reduce Golang Binary Size by 20 Percent
Here's how to reduce your golang binary size by 20%, for free.
-ldflags="-s -w" to your build and watch the output size drop by 20%.
go build -ldflags="-s -w"
This strips away a bunch of symbols that are only used by debuggers. If you don't use them, then everything else is the same, including panic stack traces.
This also makes gzip compression work better. By packaging the reduced golang binary in a
tar.gz results in a distribution 4x smaller than the original.
The article also mentions using UPX to create self-decompressing binaries. It is interesting but it's not much better than the
tar.gz combination to justify the complexity.