Remix.run Logo
inkyoto 4 days ago

OCaml was[0] very popular in the high-frequency trade programming, especially because of its high performance and predictable latency despite having a garbage collector, plus, of course, because of the correctness of the code written in it.

OCaml's GC design is a pretty simple one: two heaps, one for short-lived objects and another one for the long-lived objects, and it is a generational and mostly non-moving design. Another thing that helps tremendously is the fact that OCaml is a functional programming language[1], which means that, since values are never mutated, most GC objects are short or very short-lived and never hit the other heap reserved for the long-lived objects, and the short-lived objects perish often and do so quickly.

So, to recap, OCaml’s GC is tuned for simplicity, predictable short pauses, and easy interoperability, whereas Java’s GC is tuned for maximum throughput and large-scale heap management with sophisticated concurrency and compaction.

[0] Maybe it still is – I am not sure.

[1] It is actually a multiparadigm design, although most code written in OCaml is functional in its style.

gf000 4 days ago | parent [-]

At the same time, OCaml has a very simplistic memory layout where even integers are boxed - Java at least has primitive types.

That surely has a performance cost.

dmpk2k 4 days ago | parent [-]

Are you sure about boxed integers? Perhaps you mean floats? As far as I know Ocaml uses the typical integer/pointer divide.

orthoxerox 4 days ago | parent [-]

IIRC it has 31-bit integers, which means you can't natively work with 32-bit data without widening.

zorobo 4 days ago | parent [-]

or 63 bits on 64 bit architectures.