Parallel execution is being added to the Rust compiler front end to significantly reduce compile times, according to a November 9 announcement of the parallel rustc working group.
Currently in an experimental stage, the parallel front end is due to ship with the stable compiler next year. Developers can try parallel execution now by running the nightly compiler with the
-Z threads=8 option. When the parallel front end is run in multi-threaded mode with
-Z threads-8, measurements on “real world” code have shown that compile times can be reduced by as much as 50%. Effects vary widely based on characteristics of the code and the build configuration.
The working group said development builds are likely to see bigger improvements than release builds because release builds usually spend more time on optimizations in the back end. Further, a small number of cases compile slower in multi-threaded mode than single-threaded mode, mostly tiny programs that already compile quickly.
Noting that compile times are a “perennial concern,” the working group said Rust’s compiler performance has been continuously improved over several years. At this point, the compiler has been heavily optimized and new improvements are difficult to find. Describing parallelism as a “piece of large but high-hanging fruit,” the group said the front end uses the Rayon data parallelism library to convert sequential computations into parallel ones. Rayon leverages fine-grained parallelism.
The working group recommends using eight threads for parallel execution. Memory usage, however, can significantly increase in multi-threaded mode. This was deemed unsurprising since various parts of compilation, each requiring a certain amount of memory, now execute in parallel. Work is ongoing to improve parallel front end performance.
Developers who find any problems with the parallel front end should check issues marked with the WG-compiler-parallel label. New issues can be filed as well. Rust compilation already benefits from inter-process parallelism via the Cargo package manager and from intra-process parallelism in the back end.