Night Assemblies RUST Expands Decorating Compilation Possibilities

In the front of the Rust compiler, various tasks such as syntactic analysis, type testing, and analysis of borrowing are implemented. The support of parallel execution in these tasks allows for a significant reduction in compilation time. Pop paralleling is already available in the night assemblies of RUST and can be activated using the option “-z Threads = 8”. The plan is to include this feature in the stable branch by 2024.

The effort to reduce compilation time in RUST has been ongoing for several years. In the first 10 months of 2023, the average compilation time decreased by 13%, peak memory consumption decreased by 15%, and the size of generated files decreased by 7%. These improvements were achieved through optimization of the compiler itself. Following this, developers shifted their focus to accelerating compilation through parallelization of operations.

Previously, parallelization in RUST primarily occurred at the process level. For instance, the Cargo package manager could run multiple RustC processes to simultaneously compile different packages. Parallelization support was also present in the backend, which generated code in parts for future parallel processing by LLVM. However, the front-end still processed source code in single-air mode.

In order to enable front-end parallelization, the front-end was switched to using the rayon library. The front-end underwent significant redesign, with many parts now synchronized using mutexes and locks for atomic readings and records. When performance was tested, the new distributed implementation was up to 2% slower in single-air mode (-z Threads = 1), but the speed increased significantly with multiple threads. For example, with 8 threads (-z Threads = 8), compilation time could be reduced by 50%.

However, the results greatly depend on the environment settings and the compiled code. For very small programs that already compile quickly, multi-flow mode may actually be slower. Additionally, in multi-flow mode, memory consumption can significantly increase, with tests showing up to a 35% increase.

/Reports, release notes, official announcements.