Friday, 27 March 2009

Memory footprints: OCaml vs HLVM

Someone recently published a blog article about the sizes of values in the Ruby and OCaml programming languages.

This is also interesting in the context of HLVM because our high performance goals also require an efficient memory representation but our solution is quite different to OCaml's because HLVM is designed for numerical performance whereas OCaml was designed for symbolic performance.

The following table lists the sizes of values of several different types in OCaml and HLVM on 32-bit architectures:













TypeOCamlHLVM
unit32 bits32 bits
bool32 bits8 bits
int3132 bitsNone
int3296 bits32 bits
int64128 bits64 bits
float32None32 bits
float64128 bits64 bits
float * float320 bits128 bits
Enumeration32 bits96 bits
float64 array64+64n bits96+64n bits

Note how HLVM uses the most memory efficient representations possible for ints, floating point numbers and tuples but uses less efficient representations for reference types such as arrays and variant types. A side-effect is that heaps in HLVM contain far fewer pointers than heaps in OCaml and this greatly reduces the stress on the garbage collector.

1 comment:

jay paul said...
This comment has been removed by a blog administrator.