How to limit the amount of memory the OCaml compiler is allowed to use?



Is it possible to limit the RAM the OCaml compiler is allowed to use (at the expense of speed)?

We’re hitting the 4GB limit on CircleCI with our OCaml project now, and I can’t find the equivalents of for OCaml


@stedolan was kind enough to provide the answer to this:

the main tool for configuring space use is the space overhead parameter (OCAMLRUNPARAM’s o).
Try export OCAMLRUNPARAM="o=20" before running your program

Unlike java, you don’t specify a maximum heap size but instead a relative overhead: o=80 (the default) means that the heap is allowed to grow to the amount of live data in your program + 80%

Interestingly, @Drup points out that OCAMLRUNPARAM` affects any OCaml program, and since the compiler itself is an OCaml program, it’s affected!

@dww has also opened up a PR for the CircleCI docs for anyone else who runs across this
EDIT: PR has been merged, the new OCaml/Reason note for CircleCI is live


Note that OCAMLRUNPARAM has a few other interesting parameters which are documented here in the manual.