Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build host dependencies with opt-level 0 by default #8500

Merged
merged 1 commit into from
Jul 17, 2020

Commits on Jul 17, 2020

  1. Build host dependencies with opt-level 0 by default

    This commit updates Cargo's build of host dependencies to build them
    with optimization level 0 by default instead of matching the profile of
    the final binary.
    
    Since Cargo's inception build dependencies have, by default, been built
    in a profile that largely matches the profile of the final target
    artifact. Build dependencies, however, rarely actually need to be
    optimized and are often executing very small tasks, which means that
    optimizing them often wastes a lot of build time. A great example of
    this is procedural macros where `syn` and friends are pretty heavyweight
    to optimize, and the amount of Rust code they're parsing is typically
    quite small, so the time spent optimizing rarely comes as a benefit.
    
    The goal of this PR is to improve build times on average in the
    community by not spending time optimizing build dependencies (build
    scripts, procedural macros, and their transitive dependencies). The PR
    will not be a universal win for everyone, however. There's some
    situations where your build time may actually increase:
    
    * In some cases build scripts and procedural macros can take quite a
      long time to run!
    * Cargo may not build dependencies more than once if they're shared with
      the main build. This only applies to builds without `--target` where
      the same crate is used in the final binary as in a build script.
    
    In these cases, however, the `build-override` profile has existed for
    some time know and allows giving a knob to tweak this behavior. For
    example to get back the previous build behavior of Cargo you would
    specify, in `Cargo.toml`:
    
        [profile.release.build-override]
        opt-level = 3
    
    or you can configure this via the environment:
    
        export CARGO_PROFILE_RELEASE_BUILD_OVERRIDE_OPT_LEVEL=3
    
    There are two notable features we would like to add in the future which
    would make the impact of a change like this smaller, but they're not
    implemented at this time (nor do we have concrete plans to implement
    them). First we would like crates to have a way of specifying they
    should be optimized by default, despite default profile options. Often
    crates, like lalrpop historically, have abysmal performance in debug
    mode and almost always (even in debug builds) want to be built in
    release mode. The second feature is that ideally crate authors would be
    able to tell Cargo to minimize the number of crates built, unifying
    profiles where possible to avoid double-compiling crates.
    
    At this time though the Cargo team feels that the benefit of changing
    the defaults is well worth this change. Neither today nor directly after
    this change will be a perfect world, but it's hoped that this change
    makes things less bad!
    alexcrichton committed Jul 17, 2020
    Configuration menu
    Copy the full SHA
    dc4b695 View commit details
    Browse the repository at this point in the history