Reducing GHC Binary Sizes

2013-06-24 14:55 UTC
  • Xyne

Notes

GHC statically links files by default. This can lead to very large binary files for relatively simple applications. The following will generated a dynamically linked binary, strip it and then compress it with upx:

ghc -O2 -dynamic --make foo.hs
strip foo
upx gen

For even greater size reduction, use

ghc -O2 -dynamic --make foo.hs
strip foo
upx gen --ultra-brute

Be patient as it churns away optimizing the file size. The result will be a very small binary. In the case of the binary that led me to discover this, it resulted in a reduction from 29 MiB to 42 kiB, which is nearly 1/700 of the original size.

Contact
echo xyne.archlinux.ca | sed 's/\./@/'
Feeds
Blog News
Validation
XHTML 1.0 Strict CSS level 3 Atom 1.0