Hello!
I’m curious what OCaml compilation time is like on different sized projects. If someone from the community could drop ballpark numbers for projects sizing from ~10k, ~100k and ~1m lines I would love to hear your experience reports.
Hello!
I’m curious what OCaml compilation time is like on different sized projects. If someone from the community could drop ballpark numbers for projects sizing from ~10k, ~100k and ~1m lines I would love to hear your experience reports.
I have just compiled 10000 lines of my PDF tools to native code in 2.3s on a modern machine. If you’re short on time, the byte code version compiles in 1.3s.
Xapi (https://github.com/xapi-project/xen-api) 168.457 lines of ocaml plus around 800 lines of C (and countless dependencies) compiles on my laptop – from scratch – in slightly more than a minute. Much faster if I am just recompiling.
My personal monorepo is around 33k lines of Ocaml code and takes 33 seconds to compile using a -j7
in make
. There are a bunch of internal dependencies in there that serialize at least some compilation.
OCaml compiler itself is a sizable project, with about 300K lines of OCaml and 60K of C. My colleague Niels G. W. Serup recently done some benchmarking of how long it takes to compile it on Windows; both on Cygwin and WSL2. On a modest 2-core 8GB Windows VM it took about 0:10:46 on Cygwin and 0:05:57 on WSL2.
I have experienced something like ~4s for 40k lines in the past at INRIA, IIRC.
Yeah. On my MacBook Air, I can compile all of the OCaml compiler tools, plus all of the OPAM packages I need for my project in the time it commonly takes for the LLVM build just to compile its core libraries.
The question might be a bit misguided. OCaml language is designed to allow separate compilation. Therefore, one rarely compiles more than a few files, regardless of the project size.
So if you ask from the point of view of a developper then compilation is fast, because of separate compilation.
If you ask from the point of view of the user of a source distribution system à la opam, when any project has to be recompiled from scratch then… it depends on your expectations. If you are used to C++ then OCaml will feel way faster whereas if you are used to scripting languages then I guess it will feel slow.
Regarding speed of compiling a large compilation unit, the compiler is quite fast but some languages constructs (such as very large pattern matching of chains of conditionals) can slow it down significantly. It is then possible to disable some of the fancier compiler options to make it fast again, in my experience (flambda, sophisticated register allocation strategies…)
What is your concern? Is compilation speed important for your projects?