Skip to content

Experiment with giving higher priority to proc-macros and their dependencies #8370

Closed as duplicate

Description

@Aaron1011

Currently, the dependency queue uses the number of transitive reverse dependencies to determine how to schedule jobs:

/// The total number of packages that are transitively waiting on this package
priority: HashMap<N, usize>,

I think it would be a good idea to experiment with 'boosting' the priority of proc-macro crates and their dependencies. Unlike other crates, proc-macro crate building cannot be pipelined - since they are dynamically loaded into the compiler, any reverse-dependencies of proc-macro crates must wait for codegen, not just metadata.

By giving proc-macro crates a higher priority, we increase the likelihood that they will finish codegen by the time we are ready to start building their reverse dependencies. A similar argument applies to dependencies (not reverse-dependencies) of proc-macro crates: until rust-lang/rust#64191 is implemented, we still need to wait for all a proc-macro crates's dependencies to codegen before we can start building the proc-macro crate.

Anecdotally, I've noticed that some proc-macro dependencies (e.g. syn) seem to take a significant fraction of the total build time. By starting to build these crates earlier, we may be able to reduce the impact of their build times on the total build time.

Concretely, I think we could add a flag -Z prioritize-proc-macros to Cargo. When enabled, we could either directly increase the priority entry by a certain factor, or just break ties in priority by proc-macro (or proc-macro-dependency) status.

By using -Z timings, we can gather data on the impact of this change on build times.

Activity

  1. added
    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
    on Jun 16, 2020
  2. ehuss commented on Jun 17, 2020

    @ehuss
    Contributor

    I think it would be great to experiment with this. If you (or someone) wants to prototype it and demonstrate that it is measurably faster on some sampling of projects (and various -j values), I think it could be added without a -Z flag.

  3. domenicquirl commented on Apr 28, 2022

    @domenicquirl

    To add to this (while being unsure if this is even pursued at the moment): a similar logic applies to build scripts. For example, the now-stabilized --timings on a crate that uses openssl-sys/vendored (and thus has to build openssl from source to statically link it) shows that the critical dependency here (with some hops through openssl crates) is cc, which is built as the 7th crate total out of some hundred.

    The build script only starts running about 15 seconds later, however, leading to a very undesirable tail of compiling the handful of crates that use it at then end. The build script takes a very long time to run, so all other crates are well done by that point - if the build script was started earlier, it could have run in parallel for those 15 seconds and the whole build would be faster.

  4. added
    S-triageStatus: This issue is waiting on initial triage.
    on Nov 20, 2024
  5. epage commented on Nov 6, 2025

    @epage
    Contributor

    This was experimented with in #t-cargo > pending queue scheduling experiments @ 💬. Not seeing a specific decision but I though that we found that the results were mixed enough that we weren't willing to commit to it.

    An easier way to experiment with this in the future is #7437. I'm going to close in favor of that. If there is a reason to re-evaluate, let us know!

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

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`PerformanceGotta go fast!S-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions