Hasty Briefsbeta

Bilingual

Shrink your Go binaries with this one weird trick

3 days ago
  • Go binaries can be reduced in size by more than 6 times using linker flags and compression tools.
  • Stripping binaries with '-s -w' linker flags removes debugging information, reducing size by about 28%, while preserving stack traces for panics.
  • Using UPX compression on stripped binaries further reduces size to about 15% of the default, e.g., a 12MB binary becomes around 2.5MB.
  • The author cautions that size reduction trades off build time, complexity, performance, and debug-ability, though it may be useful for some users.
  • UPX decompression adds startup overhead, e.g., 160ms for the Go compiler and 15ms for a simple program.
  • Improvements in Go 1.7, such as conditional tree pruning and SSA savings, also contribute to smaller binary sizes.