Skip to content

Conversation

joshtriplett
Copy link
Member

Most users of the rustix crate will use a fraction of its API surface
area.

Nightly rustc provides an option -Zhint-mostly-unused to tell it to
defer as much compilation as possible, which provides a substantial
performance improvement if most of that compilation doesn't end up
happening. Cargo plumbs this option through using the new [hints]
table. This will cause users of the rustix crate to default to setting
hint-mostly-unused. (Top-level crates can override this if they wish,
using a new profile option.)

Note that setting this hint does not increase the MSRV of the rustix
crate, as old versions of Cargo will ignore it. New versions of Cargo
will respect it automatically (and, until we stabilize it, Cargo will do
nothing unless you pass -Zprofile-hint-mostly-unused to cargo).

Some sample performance numbers: this takes rustix compilation time
with all-apis enabled from 5.9s to 4.3s (a 27% improvement).

Most users of the `rustix` crate will use a fraction of its API surface
area.

Nightly rustc provides an option `-Zhint-mostly-unused` to tell it to
defer as much compilation as possible, which provides a substantial
performance improvement if most of that compilation doesn't end up
happening. Cargo plumbs this option through using the new `[hints]`
table. This will cause users of the `rustix` crate to default to setting
`hint-mostly-unused`. (Top-level crates can override this if they wish,
using a new profile option.)

Note that setting this hint does not increase the MSRV of the rustix
crate, as old versions of Cargo will ignore it. New versions of Cargo
will respect it automatically (and, until we stabilize it, Cargo will do
nothing unless you pass `-Zprofile-hint-mostly-unused` to cargo).

Some sample performance numbers: this takes `rustix` compilation time
with `all-apis` enabled from 5.9s to 4.3s (a 27% improvement).
@joshtriplett
Copy link
Member Author

The FreeBSD test failure looks entirely unrelated.

@sunfishcode
Copy link
Member

Cool! Could you also add a comment, like "most users use a fraction of our API surface area, so this reduces compile times"?

@joshtriplett
Copy link
Member Author

@sunfishcode Done.

@sunfishcode sunfishcode merged commit 9113d68 into bytecodealliance:main Jul 13, 2025
49 of 51 checks passed
@joshtriplett joshtriplett deleted the hint-mostly-unused branch July 14, 2025 04:55
sunfishcode pushed a commit that referenced this pull request Jul 15, 2025
* Use new `hints.mostly-unused`

Most users of the `rustix` crate will use a fraction of its API surface
area.

Nightly rustc provides an option `-Zhint-mostly-unused` to tell it to
defer as much compilation as possible, which provides a substantial
performance improvement if most of that compilation doesn't end up
happening. Cargo plumbs this option through using the new `[hints]`
table. This will cause users of the `rustix` crate to default to setting
`hint-mostly-unused`. (Top-level crates can override this if they wish,
using a new profile option.)

Note that setting this hint does not increase the MSRV of the rustix
crate, as old versions of Cargo will ignore it. New versions of Cargo
will respect it automatically (and, until we stabilize it, Cargo will do
nothing unless you pass `-Zprofile-hint-mostly-unused` to cargo).

Some sample performance numbers: this takes `rustix` compilation time
with `all-apis` enabled from 5.9s to 4.3s (a 27% improvement).

* Add comment to the mostly-unused hint
sunfishcode pushed a commit that referenced this pull request Jul 15, 2025
* Use new `hints.mostly-unused`

Most users of the `rustix` crate will use a fraction of its API surface
area.

Nightly rustc provides an option `-Zhint-mostly-unused` to tell it to
defer as much compilation as possible, which provides a substantial
performance improvement if most of that compilation doesn't end up
happening. Cargo plumbs this option through using the new `[hints]`
table. This will cause users of the `rustix` crate to default to setting
`hint-mostly-unused`. (Top-level crates can override this if they wish,
using a new profile option.)

Note that setting this hint does not increase the MSRV of the rustix
crate, as old versions of Cargo will ignore it. New versions of Cargo
will respect it automatically (and, until we stabilize it, Cargo will do
nothing unless you pass `-Zprofile-hint-mostly-unused` to cargo).

Some sample performance numbers: this takes `rustix` compilation time
with `all-apis` enabled from 5.9s to 4.3s (a 27% improvement).

* Add comment to the mostly-unused hint
@sunfishcode
Copy link
Member

This is now released in rustix 1.0.8.

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.

2 participants