Hasty Briefsbeta

Bilingual

Cutting Down Rust Compile Times with One Thousand Crates

a year ago
  • #Compilation
  • #Performance
  • #Rust
  • Rust compile times can be a significant bottleneck, especially for large codebases.
  • Feldera compiles SQL into Rust code, which can result in very long compile times for complex queries.
  • A large enterprise client's SQL program (8562 lines) translated to ~100k lines of Rust took 25-45 minutes to compile.
  • Compilation was single-threaded, utilizing only one core despite having a 64-core machine.
  • The majority of time was spent in LLVM passes and codegen, which are single-threaded processes.
  • Attempts to increase codegen-units did not significantly improve compile times.
  • Splitting the generated Rust code into multiple smaller crates (1106 crates) allowed parallel compilation.
  • This change reduced compile times from 30-45 minutes to just 2 minutes and 10 seconds.
  • Each crate was named using a hash of its contents, ensuring unique names and effective incremental compilation.
  • Despite the improvement, the compile time is still 7x slower than the theoretical maximum, possibly due to hardware contention or other bottlenecks.