3 ms·
> In theory, if you split your code into multiple crates, Cargo can parallelize rustc invocations. Because I have a 32-thread CPU on my Linux machine, and a 10-
by throw10920 4y ago
> In theory, if you split your code into multiple crates, Cargo can parallelize rustc invocations. Because I have a 32-thread CPU on my Linux machine, and a 10-thread CPU on my macOS machine, I expect unlocking parallelization to reduce build times.
Why can't Cargo parallelize rustc invocations per-file, like C++ can?
- lights0123 4y agorustc needs to look at the entire crate because there's no header files that provide information about other items like C++. rustc does parallelize internally though: https://doc.rust-lang.org/rustc/codegen-options/index.html#codegen-units https://doc.rust-lang.org/rustc/codegen-options/index.html#c...
- throw10920 4y ago> Increasing parallelism may speed up compile times, but may also produce slower code Why do I have to make the choice between faster compiles and faster binaries?
- lights0123 4y agoThe exact same thing happens in C++—when you're not using LTO, you can pass multiple source files to the compiler at a time to allow these files to be optimized together, but keeping them separated at a file-level prevents optimizations such as inlining functions between them. Compiling with and without optimizations is another example of that choice.
- steveklabnik 4y agoBecause the unit of compilation is a crate, not a file. You don't pass each file to rustc, you pass the crate root only.