Polymorphisation: Improving Rust compilation times through intelligent monomorphisation

Rust is a new systems programming language, designed to provide memory safety while maintaining high performance. One of the major priorities for the Rust compiler team is to improve compilation times, which is regularly requested by users of the language. Rust’s high compilation times are a result of many expensive compile-time analyses, a com- pilation model with large compilation units (thus requiring incremental compilation techniques), use of LLVM to gen- erate machine code, and the language’s monomorphisation strategy. This paper presents a code size optimisation, im- plemented in rustc, to reduce compilation times by intelli- gently reducing monomorphisation through “polymorphisa- tion” - identifying where functions could remain polymor- phic and producing fewer monomorphisations. By reduc- ing the quantity of LLVM IR generated, and thus reduc- ing code generation time spent in LLVM by the compiler, this project achieves 3-5% compilation time improvements in benchmarks with heavy use of closures in highly-generic, frequently-instantiated functions.

This thread was posted by one of our members via one of our news source trackers.