DEV Community

Vedran Vidovic
Vedran Vidovic

Posted on • Edited on

Trimming go binaries of dpcmder - trimming a compression time :)

Preparing for the next release of dpcmder I wanted to do some more testing of release binaries compression achievable using UPX and find out I can achieve 40 times faster compression just by changing single upx compression flag.

Note: this continues where the last post about dpcmder binaries compression finished.

I realized there are some upx flags I didn't test (for example "--ultra-brute" or "--best") and read a bit more about them. In the end, it seems (for dpcmder binaries at least) best compression results are achieved using the "--lzma" flag:

$ time upx --lzma release.lzma/*
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2013
UPX 3.91        Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 30th 2013

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
   9146368 ->   2812760   30.75%  linux/ElfAMD   dpcmder-linux-amd64           
   9697256 ->   2789376   28.76%   Mach/AMD64    dpcmder-mac-amd64             
   8932352 ->   2610688   29.23%    win64/pe     dpcmder-win-amd64.exe         
   --------------------   ------   -----------   -----------
  27775976 ->   8212824   29.57%                 [ 3 files ]

Packed 3 files.

real    0m23.254s
user    0m22.911s
sys 0m0.196s

Seems that the "--brute" flag makes upx tries many different algorithms and selects one which achieves the best result. The "--ultra-brute" flag tries even more compression algorithms so it takes even more time. In my case (dpcmder binaries built on my Linux machine) best result is achieved using the lzma compression algorithm. As you can see from outputs of both upx run timings, result compression is exactly the same while time spent for compression is drastically faster (more than 40 times) when using "--lzma" flag.

$ time upx --brute release.brute/*
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2013
UPX 3.91        Markus Oberhumer, Laszlo Molnar & John Reiser   Sep 30th 2013

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
   9146368 ->   2812760   30.75%  linux/ElfAMD   dpcmder-linux-amd64           
upx: release.brute/dpcmder-linux-amd64.upx: UnknownExecutableFormatException
   9697256 ->   2789376   28.76%   Mach/AMD64    dpcmder-mac-amd64             
   8932352 ->   2610688   29.23%    win64/pe     dpcmder-win-amd64.exe         
   --------------------   ------   -----------   -----------
  27775976 ->   8212824   29.57%                 [ 3 files ]

Packed 3 files.

real    15m39.952s
user    15m37.567s
sys 0m1.408s

Top comments (0)