Description
UPDATE: There are some mentoring instructions below if you're interested in looking into this issue.
NB: Part of the roadmap issue on incremental compilation.
Currently the compiler translates all codegen units into LLVM modules and then runs LLVM on all of them in parallel. In the context of incremental compilation, where there can be hundreds of codegen units for a single crate, but also for non-incremental builds with a high number of codegen units, this can mean a lot of memory pressure -- e.g. for Servo's script
crate that's more than 10 GB peak memory usage (while otherwise it's around 4.5 GB).
There's no real need to keep more LLVM modules in memory than are currently being worked on. Two possible solutions:
- If the compiler uses
N
LLVM threads, start persisting LLVM modules to disk at theN+1
st and reload them later for optimization and codegen. That's probably relatively easy to implement but involves more disk I/O than necessary. - Translate only
N
codegen units to LLVM modules, translate them all the way to object files, then go back and translate the next codegen unit. This has the advantage that we would not need to temporarily store anything on disk, but we would need to keep thetcx
in memory as long as there are still untranslated codegen units. It would also require a much bigger refactoring than the first approach.
Any other ideas?
cc @rust-lang/compiler @rust-lang/tools @nagisa