OxCaml: Performance Extensions to OCaml
OxCaml is Jane Street's set of extensions to OCaml for performance engineering. This page gives an overview of its main features, where to learn more, and what Tarides has contributed.
What OxCaml is
In the words of oxcaml.org: "OxCaml is a fast-moving set of extensions to the OCaml programming language. It is both Jane Street's production compiler, as well as a laboratory for experiments focused towards making OCaml better for performance-oriented programming."
Main features
- Stack allocation. Values that don't outlive their scope can live on the stack instead of the heap. Stack allocations never trigger the garbage collector, so they suit low-latency code that must not allocate on the heap.
- Unboxed types. Control over how your data is laid out in memory and in registers.
- Modes. Properties of values that the compiler infers and checks alongside types: types describe what data is, modes describe how it is used.
- Uniqueness. Values
at the
uniquemode have a single reference, which the compiler checks, so an operation such as freeing memory can't lead to a use-after-free. - Kinds. Types get classified too, for example by whether their values travel in floating-point registers or can be ignored by the garbage collector.
- Data-race-free parallelism. The mode system tracks how values are shared between parallel tasks, so that they can be used safely in parallel.
- Comprehensions.
Build lists and arrays with set-builder notation, as in Python or Haskell.
Comprehensions are still in beta and need the
-extension-universe betacompiler flag.
How it relates to OCaml
From OxCaml's documentation: "It is a goal of the OxCaml project to, eventually, with the support of the OCaml community, integrate these extensions into upstream OCaml."
To try it, follow the installation instructions on oxcaml.org.
What Tarides contributes
- Tarides engineers ported two OxCaml features to upstream OCaml: immutable arrays (OCaml 5.4) and polymorphic parameters (OCaml 5.5). The OCaml changelog credits them jointly with the features' original Jane Street authors.
- OxCaml's documentation was written by the OxCaml developers at Jane Street, "with contributions from collaborators at the University of Cambridge and at Tarides".
Need high-performance OCaml? Talk to us
A free call with our team, without commitment. Tell us about your system and we'll tell you honestly where we can help.
