Skip to content

Call for Testing: Speeding up compilation with hint-mostly-unused #1662

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 9 commits into
base: master
Choose a base branch
from

Conversation

joshtriplett
Copy link
Member

@joshtriplett joshtriplett commented Jul 13, 2025

This blog post serves as a call for testing on the hint-mostly-unused
feature: giving people guidance on how it can help and how to use it, providing
sample performance numbers, asking for specific testing, and pointing people to
a tracking issue for feedback.

Rendered

@joshtriplett
Copy link
Member Author

cc @rust-lang/cargo

@joshtriplett joshtriplett force-pushed the call-for-testing-hint-mostly-unused branch 3 times, most recently from 1bf9f52 to ee5040b Compare July 13, 2025 07:11
Copy link
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Great work! Left two comments.

@joshtriplett joshtriplett force-pushed the call-for-testing-hint-mostly-unused branch from ee5040b to b5846cb Compare July 13, 2025 09:19

## Background

Some crates provide comprehensive APIs with a very large surface area, yet many
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps it will help intuition to say this is for APIs that are monomorphic? Not sure how to put that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I attempted to cover this; let me know how the new version looks.


Note that this option does not provide a universal performance improvement for
every crate. Using it for crates whose API surface is mostly used, and/or used
in multiple different crates or binaries (e.g. multiple test binaries that each
Copy link
Member

Choose a reason for hiding this comment

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

I think this explanation really undersells the downside. The problem is that when misused, the flag either completely removes CGU partitioning or causes more items to be compiled in multiple CGUs than before. The way this paragraph is written currently makes it seem like the downsides don't apply if I know have one bin target and no tests.

Copy link
Member Author

@joshtriplett joshtriplett Jul 13, 2025

Choose a reason for hiding this comment

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

This paragraph does also explicitly say it's a bad idea for crates whose API surface is mostly used.

I'll try to make this paragraph clearer and more emphatic.

Copy link
Member Author

Choose a reason for hiding this comment

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

@saethlin I've now expanded this paragraph, and made it much more emphatic about the potential downsides. Let me know if that looks better.

@joshtriplett joshtriplett force-pushed the call-for-testing-hint-mostly-unused branch from 4b90258 to f76bfcc Compare July 13, 2025 19:16
## Background

When building a Rust library crate, the compiler generates compiled code for as
much of the crate as it can (everything that isn't generic and isn't inlined),
Copy link
Member

@Noratrieb Noratrieb Jul 14, 2025

Choose a reason for hiding this comment

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

Suggested change
much of the crate as it can (everything that isn't generic and isn't inlined),
much of the crate as it can (everything that isn't generic and doesn't have `#[inline]`),

We should avoid using the adjective "inlined" for functions that have the inline attribute (same about using the verb inline for adding the attribute), as that adjective is more commonly used for functions that actually have been inlined by the optimizer. Let's avoid this confusion and be very explicit about the attribute.

I'm pleased to announce, and call for testing of, the nightly-only `rustc`
`-Zhint-mostly-unused` option, and the corresponding nightly Cargo features
`profile.hint-mostly-unused` and `hints.mostly-unused`. These options can help
accelerate your Rust compile time in some cases, by avoiding compilation of
Copy link
Member

Choose a reason for hiding this comment

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

"by avoiding compilation" may be interpreted as saying we will skip type-checking and/or borrow-checking. Which is not true in the current implementation. But maybe we want to leave open the possibility of doing so in the future?

I don't have a particular suggestion or concern here, I just want to make sure you mean the implication I'm reading.

Comment on lines +27 to +28
can take a disproportionate amount of the entire compilation time of your
top-level crate.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
can take a disproportionate amount of the entire compilation time of your
top-level crate.
can take a disproportionate fraction of the entire compilation time for a full build.

Because adding -Zhint-mostly-unused will increase the compile time of the top-level crate, while lowering the compile time of the entire multi-crate build.

Comment on lines +70 to +71
code generation for those items repeatedly. In particular, avoid using this
hint for crates whose API surface is mostly used, and/or used in multiple
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
code generation for those items repeatedly. In particular, avoid using this
hint for crates whose API surface is mostly used, and/or used in multiple
code generation for those items repeatedly. In particular, this hint will
probably regress compile time if applied to crates whose API surface is
mostly used, and/or used in multiple

Comment on lines +76 to +77
it applies obvious and substantial wins for your users. Never apply it across
the board to all your dependencies.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it applies obvious and substantial wins for your users. Never apply it across
the board to all your dependencies.
it applies obvious and substantial wins for your users. Applying it across
the board to all your dependencies will probably go poorly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants