Skip to content

trans/LLVM: Don't keep all LLVM modules in memory at the same time #39280

Closed
@michaelwoerister

Description

@michaelwoerister

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:

  1. If the compiler uses N LLVM threads, start persisting LLVM modules to disk at the N+1st and reload them later for optimization and codegen. That's probably relatively easy to implement but involves more disk I/O than necessary.
  2. 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 the tcx 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationA-concurrencyArea: ConcurrencyA-incr-compArea: Incremental compilationC-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-compilememIssue: Problems and improvements with respect to memory usage during compilation.I-compiletimeIssue: Problems and improvements with respect to compile times.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions