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 https://circleci.com/docs/1.0/oom/#setting-memory-limits-for-the-jvm for OCaml

2 Likes

@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 Update oom with instructions for OCaml/Reason by dwwoelfel · Pull Request #1499 · circleci/circleci-docs · GitHub.
EDIT: PR has been merged, the new OCaml/Reason note for CircleCI is live Welcome to CircleCI Documentation - CircleCI

3 Likes

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

2 Likes