jckuester / awsweeper

A tool for cleaning your AWS account
Mozilla Public License 2.0
468 stars 45 forks source link

Shrink the size of the binary #54

Open kadaan opened 4 years ago

kadaan commented 4 years ago

Using UPX you can shrink the size of the binaries from ~100mb to ~25mb. The settings I used were upx -9 <BINARY>.

$ upx -9 awsweeper
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2018
UPX git-716d20  Markus Oberhumer, Laszlo Molnar & John Reiser   Aug 27th 2018

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
 118215644 ->  25976848   21.97%   macho/amd64   awsweeper

Packed 1 file.
skyzyx commented 4 years ago

This just means that startup time is longer.

For an explanation, see Why are my Go executable files so large?, the section header titled "Of size/performance trade-offs and use cases".

When is this trade-off warranted?

  • if a program is executed often (e.g. microservice, system tools), then it is worth accelerating its start-up time at the cost of an increase in size. If, moreover, the program is small, with relatively few functions, (a reasonable assumption for programs executed often, like microservices or system tools), the increase in size incurred byruntime.pclntab will be negligible and thus have no significant impact on usability: file transfers, deployments, orchestration, etc.In that case, the Go 1.2 design is sound and warranted.

  • if, in contrast, a program is executed rarely (e.g. a system service that runs continuously in the background, like, say… a database server), then the start-up time can be amortized throughout the lifetime of the process. The performance benefit of accelerating start-up is then not so clear. If, moreover, the program is large, with tens of thousands of of functions (a reasonable assumption for complex, feature-driven enterprise software like … database servers), the increase in size incurred by runtime.pclntab becomes inconveniently significant. This makes the Go 1.2 design … not so advantageous.