Skip to content

Add [hints] table in Cargo.toml, and a hints.mostly-unused hint #15673

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

joshtriplett
Copy link
Member

The [hints] table in a Cargo.toml manifest provides optional
information that Cargo can use for building the package, and will use
even when using the package as a dependency. All hints can be safely
ignored, and Cargo only warns about unknown hints, but does not error.
This allows packages to use hints without depending on new Cargo.

Add a mostly-unused hint, which allows a package to hint that most
users of the package will not use most of its items. This is useful for
improving the build performance of crates with large dependencies.

Crates can override this hint using hint-mostly-unused = false in
their profile for a dependency.


In the future, this same mechanism could be used for other hints, such as
min-opt-level.

How to test and review this PR?

This PR is built atop #15643 . I'd
suggest reviewing that PR separately, then just reviewing the new commits in
this PR.

The new "hints" testsuite module demonstrates the expected behavior of hints.

Like #15643 , the nightly-only tests
will only pass once rust-lang/rust#135656 has been
merged into Rust.

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-profiles Area: profiles A-unstable Area: nightly unstable support labels Jun 16, 2025
@jeffparsons
Copy link

Sorry if this is the wrong place for this, but I'd love to see how this affects a simple binary using the aws-sdk-ec2 crate. I think if it is able to shave much time / memory consumption off those "worst offenders" then that would make a pretty compelling case for its value.

@joshtriplett
Copy link
Member Author

Note: should add a test for [hints] parsing to robustly handle a key it knows but syntax it doesn't know (because it might be future syntax).

@joshtriplett
Copy link
Member Author

joshtriplett commented Jun 17, 2025

Sorry if this is the wrong place for this, but I'd love to see how this affects a simple binary using the aws-sdk-ec2 crate. I think if it is able to shave much time / memory consumption off those "worst offenders" then that would make a pretty compelling case for its value.

For a crate depending on aws-sdk-ec2, a release build went from 4m07s to 2m04s, and a non-release build went from 2m26s to 1m28s.

@epage epage added the T-cargo Team: Cargo label Jun 17, 2025
@joshtriplett joshtriplett force-pushed the hints branch 5 times, most recently from 02f4153 to 9812504 Compare June 18, 2025 07:01
Copy link
Contributor

@epage epage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just waiting on #15643

@epage
Copy link
Contributor

epage commented Jun 18, 2025

@rfcbot fcp merge

This insta-stabilizes a new [hints] table to Cargo.toml that affects building this as a dependency. As these are just hints, there are no guarantees about what will actually be done, including us removing the table completely. As such, unstable fields do not error and wrongly-shaped fields do not error.

While this is blocked on rustc, I figured we could run our FCP in parallel.

@rfcbot
Copy link
Collaborator

rfcbot commented Jun 18, 2025

Team member @epage has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period An FCP proposal has started, but not yet signed off. disposition-merge FCP with intent to merge labels Jun 18, 2025
@joshtriplett joshtriplett marked this pull request as ready for review June 20, 2025 05:33
@rustbot
Copy link
Collaborator

rustbot commented Jun 20, 2025

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2025
These tests show what prior versions of Cargo will do with hints.
The subsequent addition of support for hints will modify these tests to
reflect the corresponding changes to Cargo.
…vior)

These tests demonstrate the behavior of current Cargo, and will be
changed when adding `hints.mostly-unused` to reflect the new behavior.
The `[hints]` table in a `Cargo.toml` manifest provides optional
information that Cargo can use for building the package, and will use
even when using the package as a dependency. All hints can be safely
ignored, and Cargo only warns about unknown hints, but does not error.
This allows packages to use hints without depending on new Cargo.

Add a `mostly-unused` hint, which allows a package to hint that most
users of the package will not use most of its items. This is useful for
improving the build performance of crates with large dependencies.

Crates can override this hint using `hint-mostly-unused = false` in
their profile for a dependency.
Make it only a warning, not an error, to have a hint value of the wrong
type.
@joshtriplett
Copy link
Member Author

Another fun benchmark number for this, using --timings:

I built a crate that depended on the windows crate, with all of its "Graphics*" and "UI*" features enabled.

Without hint-mostly-unused, windows took 15.1s, of which 49% was codegen.

With hint-mostly-unused, windows took 7.5s, of which 1% was codegen.

@joshtriplett joshtriplett added the I-nominated-to-discuss To be discussed during issue triage on the next Cargo team meeting label Jun 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-documenting-cargo-itself Area: Cargo's documentation A-manifest Area: Cargo.toml issues A-profiles Area: profiles A-unstable Area: nightly unstable support disposition-merge FCP with intent to merge I-nominated-to-discuss To be discussed during issue triage on the next Cargo team meeting proposed-final-comment-period An FCP proposal has started, but not yet signed off. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants