Skip to content

Tracking Issue for making incremental compilation the default for Release Builds #57968

@michaelwoerister

Description

@michaelwoerister
Member

Since incremental compilation supports being used in conjunction with ThinLTO the runtime performance of incrementally built artifacts is (presumably) roughly on par with non-incrementally built code. At the same time, building things incrementally often is significantly faster ((1.4-5x according to perf.rlo). As a consequence it might be a good idea to make Cargo default to incremental compilation for release builds.

Possible caveats that need to be resolved:

  • The initial build is slightly slower with incremental compilation, usually around 10%. We need to decide if this is a worthwhile tradeoff. For debug and check builds everybody seems to be fine with this already.
    Some crates, like style-servo, are always slower to compile with incr. comp., even if there is just a small change. In the case of style-servo that is 62 seconds versus 64-69 seconds on perf.rlo. It is unlikely that this would improve before we make incr. comp. the default. We need to decide if this is a justifiable price to pay for improvements in other projects.
    Even if incremental compilation becomes the default, one can still always opt out of it via the CARGO_INCREMENTAL flag or a local Cargo config. However, this might not be common knowledge, the same as it isn't common knowledge that one can improve runtime performance by forcing the compiler to use just one codegen unit.
    It still needs to be verified that runtime performance of compiled artifacts does not suffer too much from switching to incremental compilation (see below).

Data on runtime performance of incrementally compiled release artifacts

Apart from anectodal evidence that runtime performance is "roughly the same" there have been two attempts to measure this in a more reliable way:

  1. PR [experiment] Benchmark incremental ThinLTO'd compiler. #56678 did an experiment where we compiled the compiler itself incrementally and then tested how the compiler's runtime performance was affected by this. The results are twofold:
    1. In general performance drops by 1-2% (compare results for clean builds)
    2. For two of the small test cases (helloworld, unify-linearly) performance drops by 30%. It is known that these test cases are very sensitive to LLVM making the right inlining decisions, which we already saw when switching from single-CGU to non-incremental ThinLTO. This is indicative that microbenchmarks may see performance drops unless the author of the benchmark takes care of marking bottleneck functions with #[inline].
  2. For a limited period of time we made incremental compilation the default in Cargo (Make incremental compilation the default for all profiles. cargo#6564) in order to see how this affected measurements on lolbench.rs. It is not yet clear if the experiment succeeded and how much useful data it collected since we had to cut it short because of a regression (Nightly regression: Can't perform LTO when compiling incrementally #57947). The initial data looks promising: only a handful of the ~600 benchmarks showed performance losses (see https://lolbench.rs/#nightly-2019-01-27). But we need further investigation on how reliable the results are. We might also want to re-run the experiment since the regression can easily be avoided.

One more experiment we should do is compiling Firefox because it is a large Rust codebase with an excellent benchmarking infrastructure (cc @nnethercote).

cc @rust-lang/core @rust-lang/cargo @rust-lang/compiler

Activity

added
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.
A-incr-compArea: Incremental compilation
T-coreRelevant to the core team, which will review and decide on the PR/issue.
T-cargoRelevant to the cargo team, which will review and decide on the PR/issue.
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
on Jan 29, 2019
joshtriplett

joshtriplett commented on Jan 29, 2019

@joshtriplett
Member
michaelwoerister

michaelwoerister commented on Jan 29, 2019

@michaelwoerister
MemberAuthor

I don't think we should change the default to something that has any runtime performance cost.

I'm not sure. The current default already has a quite significant runtime performance cost because it's using ThinLTO instead of -Ccodegen-units=1.

alexcrichton

alexcrichton commented on Jan 29, 2019

@alexcrichton
Member

We've had a ton of discussions before about comiple time and runtime tradeoffs, see #45320 and #44941 for just a smattering. We are very intentionally not enabling the fastest compilation mode with cargo build --release by default today, and an issue like this is a continuation of that.

joshtriplett

joshtriplett commented on Jan 30, 2019

@joshtriplett
Member

@alexcrichton To avoid ambiguity, what do you mean by "fastest compilation mode" here?

I certainly think we don't need to worry about compiling as fast as possible, but I don't think our default compile should pay a runtime performance penalty like this.

alexcrichton

alexcrichton commented on Jan 30, 2019

@alexcrichton
Member

Ah by that I mean that producing the fastest code possible. Producing the fastest code by default for --release would mean things like LTO, enabling PGO, customizing the LLVM pass manager to just rerun itself to either a fixed point or until some amount of time lapses, etc.

Lokathor

Lokathor commented on Feb 2, 2019

@Lokathor
Contributor

So if release is a "best effort at being fast while still finishing the build sometime today", can we just add a different profile for "really the fastest but it'll take a day to build".

CryZe

CryZe commented on Feb 2, 2019

@CryZe
Contributor

Yeah I'm honestly thinking that it may be time for a profile between debug and release, such that there is these use cases:

  • Debug: The code is compiled such that you have the best experience trying to remove bugs.
  • "Development" / "Optimized": The code is incrementally compiled with some optimizations, such that it's suitable for fast development cycles and using it for everyday programming.
  • Release: The code is heavily optimized, such that it can be published.

At the moment I'm seeing lots of people either sacrifice the debug profile for that "Development" use case (bumping optimization levels, but reducing the debugability of the project) or sacrifice the release profile by reducing optimizations, both are kind of suboptimal.

29 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-incr-compArea: Incremental compilationC-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCI-compiletimeIssue: Problems and improvements with respect to compile times.S-tracking-design-concernsStatus: There are blocking design concerns.T-cargoRelevant to the cargo team, which will review and decide on the PR/issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-compiler-performanceWorking group: Compiler Performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@alexcrichton@eddyb@joshtriplett@lnicola

        Issue actions

          Tracking Issue for making incremental compilation the default for Release Builds · Issue #57968 · rust-lang/rust