3

When I compile my Snap webapp (to deploy it to production server), it comes out to 19MB! What gives? Is this normal? Am I doing something wrong?

My site only has 3 static pages, basically snap's init project.

mightybyte
  • 7,282
  • 3
  • 23
  • 39
Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272

1 Answers1

2

I guess Snap pulls a lot of dependencies. One solution to this problem, which unfortunately affects the (initial) compilation time is to install libraries your project depend on with --split-objs option. That will generate a ton of different object but will make the final executable a lot smaller, like 2-4 times smaller.

$ cabal install --enable-split-objs

If you already have the libraries installed you will need to remove them first, install a fresh GHC or use sandbox with it's own package set.

You should also use strip command (cabal does this automatically in some cases).

Additionally you may consider using upx for compressing executables and finally rsync to upload minimally different executable to the server.

Using shared libraries (cabal install --enable-shared) may or may not help here: I didn't experiment with that option.

Tener
  • 5,280
  • 4
  • 25
  • 44
  • Should I do this both on the local server and on the production? Or just ensuring that production has Haskell is sufficient? – Andriy Drozdyuk Jul 04 '12 at 01:21
  • I tried both `--enable-split-objs` and `--enabled-shared` on my snap project and neither one seems to work. The binary is exactly the same size. – Andriy Drozdyuk Jul 04 '12 at 03:31
  • @drozzy You need to build the libraries that your project depend on with these options. Just recompiling your project won't do much. I would recommend starting with a clean installation of GHC for this purpose or using sandboxing solution for this (like virthualenv or something). – Tener Jul 04 '12 at 10:03
  • Thanks, do I then need to install GHC and all the dependencies on my production server? Have you ever used something like [bsdiff](http://www.daemonology.net/bsdiff/)? – Andriy Drozdyuk Jul 18 '12 at 18:14