[erlang-questions] Making a minimal distributable program in Erlang.

Richard A. O'Keefe <>
Fri Sep 22 02:08:40 CEST 2017

On 21/09/17 9:00 PM, Joe Armstrong wrote:

> I don't know how squashable the object code is - it might be nice to compress
> the object code for (Mac,Windows,Linux) and put them in the Data area
> of the program, then decompress them and load them on-the-fly.

I happened to have a 2 MB a.out handy on my Mac.
gzip -9 reduced it to 30% of the original size.
I recompiled it from source on a SPARC/Solaris
box.  gzip -9 reduced that to 21% of its original
size.  (The a.out was bigger on the SPARC, but
the a.out.gz was smaller.)

Object file formats are optimized for speed of
loading and for being able to page from them,
so it's not surprising that they are pretty squashable.
It seems rather likely that a custom compressor could
beat gzip.

The BEAM code of course would be system-independent.
All the BEAM files in an Erlang/OTP distribution I
had handy came to 170 MB.  That did *not* compress
well: gzip -9 just reduced it to (not by) 75%.
I suspect that a custom compressor could do better.
Taking all the .erl files in the same distribution
(and yes, I know that is an under-estimate, but it
isn't a *huge* underestimate) and stripping out the
comments gave me 19 MB, which gzipped to 2.2 MB,
so sending the sources instead of BEAM files would
compress the Erlang part to 1.3% (to, not by).

Again, BEAM files were not designed to save space.
But this does very strongly suggest that BEAM files
are not a good *distribution* format, and that a
system using intelligently compress ASTs like
Thomas Kistler's Juice system for Oberon might do
very well, an observation I've made before.

More information about the erlang-questions mailing list