Parallelizing Compilation: In-Process vs Multi-Process

5 points by Riolku


I'm not sure if there are already good names for this, but I can't find anything useful when I look online.

Obviously, when compiling programs, parallelizing the work is crucial. There seem to be two main approaches:

I'm looking into this because I'm looking at designing a programming language, and I have fast compilation as an explicit goal. Zig and Rust obviously have some of the same ideas but wildly different compilation speeds. C is known to be quite fast to compile, while C++ templates are slow(?).

In terms of parallelization, why is it that a parallel compiler seems to be the choice for newer languages? Is this a coincidence or explicitly required because of e.g. circular imports?

Student

P sure it’s because modern languages don’t compile single files without being affected by what’s in other files. C has that property which makes spawning compilers feasible.

sanxiyn

The concept you are looking for is compilation unit. Compilation unit is code that needs to be compiled together. Separate compilation is compilation of different compilation units. Multi-process compilation parallelization can parallelize between compilation units but can't parallelize within a compilation unit.

So the size of a compilation unit is the variable affecting decision of multi-process compilation parallelization vs in-process compilation parallelization. Yes, circular imports can increase the size of a compilation unit. Rust, Zig, and Haskell have large compilation unit. C and OCaml have small compilation unit.