Skip to content

tweak notes for optimize(speed/size) - #2415

Open
RalfJung wants to merge 7 commits into
rust-lang:masterfrom
RalfJung:optimize
Open

RalfJung wants to merge 7 commits into
rust-lang:masterfrom
RalfJung:optimize

Conversation

@RalfJung

@RalfJung RalfJung commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

I found it odd that the comment for optimize(size/speed) is so far away from the one for optimize(none), so I moved it down and also updated it based on the discussion on Zulip.

Also see rust-lang/rust#166002 which adjusts rustc to make mir-opt and LLVM behavior more consistent.

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Nov 15, 2026
Let's make some editorial fixes and revisions to the tweaked note
about the `optimize` attribute.
The note says that `optimize(size)` and `optimize(speed)` don't do
much at `-C opt-level=0` or at `-C opt-level=1`.

That's true for `-C opt-level=0`.  But at `-C opt-level=1`, the
compiler does meaningful optimization, and `optimize(size)`
meaningfully affects the results.

Let's trim the claim to `-C opt-level=0` only.
We say that `-C opt-level=0` disables most of the LLVM optimization
pipeline.  Let's be more precise and say exactly what it doesn't
disable.
The `optimize` attribute affects both optimization and code
generation.  What we're saying in this note is most accurate if scoped
to speak only about the effect on optimization, so let's scope it in
that way.
In the note, we say that marking a function with `optimize(size)`
affects optimization at `-C opt-level=2` and higher.  But that's
incomplete.  It actually affects optimization at all levels other than
`-C opt-level=0` and `-C opt-level=z`.  Let's say that.
There's more to the story of the `optimize` attribute than just the
effect on optimization.  It also affects code generation.  Let's
discuss this in a new note.
@traviscross

Copy link
Copy Markdown
Contributor

Thanks @RalfJung. I've pushed some revisions. (The situation is always a bit more complicated.) Please have a look.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: The marked PR is awaiting review from a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants