-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Tracking issue for RFC 2412, "The optimize attribute" #54882
Comments
@nagisa I've added all unresolved questions from the RFC for completeness; the first 2 may already be resolved, if you feel that's the case; tick the boxes. |
Marking as resolved just because these never came up during the RFC discussion, especially since the attribute design does not prohibit adding these as a feature later on. I’m assigning myself for now as I intend to implement this. Failing to dedicate time for this within two or so weeks I pledge to write up some instructions. |
I’ve implementation for |
Would this allow a crate ( |
The implementation for Another thing that I’ve realised just now is that I never tested and is implemented incorrectly currently is "unused_attribute". The lint does not fire for the attribute applied to non-function items. This should also be fixed before any sort of stabilisation can proceed. My recent observation is that |
@nagisa Any updates re. the remaining work? |
+1 For this, in C++ code bases I've worked on this was very useful in a few cases;
I'd love to see the |
Triage: not aware of any movements here lately. |
So please, add support of |
Would just like to add my two cents to this: After working on many embedded projects on processors with limited storage space it was critical to be able to change the optimization levels, here's some use-cases:
|
Just wanted to hop in to agree that |
Another two cents:
Perhaps some options when building crates like 'ignore optimize attribute', 'default', 'debug', 'release', 'size', 'speed', 'none' that can be applied per-dependency which overrides the default optimization level. e.g. you would likely set 'core' and 'std' to 'release', and perhaps a bugged workspace crate to 'debug' and build using '--release' so you can debug the bugged workspace crate and not have everything in the bugged workspace crate optimized away.
|
@hydra Cargo already let's you override the optimization level for dependencies, it's great: https://doc.rust-lang.org/nightly/cargo/reference/profiles.html#overrides I use it for gamedev so that ggez/bevy/etc are built optimized but my game logic is debug. But per function control is much more surgical and a nice feature. |
@jgarvin cool, i'll check that out. With regard to the per-module comment above I was sort of wanting something between a surgeon's knife (function attribute) and a spoon (dependency level) though. 😃 |
In 2019 @nagisa mentioned that the propagation mechanism was not implemented. Is that still the case? We discussed this in today's @rust-lang/lang meeting, and we're interested in getting this over the finish line. We also do see the multiple people asking after |
The propagation mechanism still hasn't been implemented and at this point I'm quite confident that it is going to be something we will want to have as a more general mechanism (e.g. this is desirable for attributes such as My feeling is that we should actually remove the part about propagation from the RFC scope for this specific attribute and work on it separately, defining semantics for propagation that make sense in a broader context. (It might very well be the case that semantics specified in the |
As one concrete use case for Unfortunately, this can make debugging somewhat challenging. We currently employ a mix of |
Optimization prevention is also strongly related to security issues. To prevent timing side-channel attacks against some cryptographic algorithm implementations, we must ensure some operations are constant-time, i.e., their execution time should not depend on the secret input, if any. OpenSSL, libsodium and many other crypto libraries all implement constant-time functions like swap, sort, etc. The memory safety and the strong guarantee of type safety provided by the Rust programming language make it a good candidate for implementing security-sensitive applications like blockchain, and zero-knowledge-proof systems. However, the lack of optimization control subtly undermines the robustness of these systems because Rust only has some sort of blackbox function The subtle crate provides a best-effort way to implement constant-time crypto algorithms using |
…compiler-errors Emit an error if `#[optimize]` is applied to an incompatible item rust-lang#54882 The RFC specifies that this should emit a lint. I used the same allow logic as the `coverage` attribute (also allowing modules and impl blocks) - this should possibly be changed depending on if it's decided to allow 'propogation' of the attribute.
Rollup merge of rust-lang#128458 - clubby789:optimize-unused-attr, r=compiler-errors Emit an error if `#[optimize]` is applied to an incompatible item rust-lang#54882 The RFC specifies that this should emit a lint. I used the same allow logic as the `coverage` attribute (also allowing modules and impl blocks) - this should possibly be changed depending on if it's decided to allow 'propogation' of the attribute.
cc #128488 #128581 (comment) |
Add `#[optimize(none)]` cc rust-lang#54882 This extends the `optimize` attribute to add `none`, which corresponds to the LLVM `OptimizeNone` attribute. Not sure if an MCP is required for this, happy to file one if so.
I have opened #129063 which will add some uses of |
For anyone wanting to try (on
Someone please update "Feature Name" at https://rust-lang.github.io/rfcs/2412-optimize-attr.html. |
Apply size optimizations to panic machinery and some cold functions * std dependencies gimli and addr2line are now built with opt-level=s * various panic-related methods and `#[cold]` methods are now marked `#[optimize(size)]` Panics should be cold enough that it doesn't make sense to optimize them for speed. The only tradeoff here is if someone does a lot of backtrace captures (without panics) and printing then the opt-level change might impact their perf. Seems to be the first use of the optimize attribute. Tracking issue rust-lang#54882
Apply size optimizations to panic machinery and some cold functions * std dependencies gimli and addr2line are now built with opt-level=s * various panic-related methods and `#[cold]` methods are now marked `#[optimize(size)]` Panics should be cold enough that it doesn't make sense to optimize them for speed. The only tradeoff here is if someone does a lot of backtrace captures (without panics) and printing then the opt-level change might impact their perf. Seems to be the first use of the optimize attribute. Tracking issue rust-lang#54882
Apply size optimizations to panic machinery and some cold functions * std dependencies gimli and addr2line are now built with opt-level=s * various panic-related methods and `#[cold]` methods are now marked `#[optimize(size)]` Panics should be cold enough that it doesn't make sense to optimize them for speed. The only tradeoff here is if someone does a lot of backtrace captures (without panics) and printing then the opt-level change might impact their perf. Seems to be the first use of the optimize attribute. Tracking issue rust-lang#54882
Apply size optimizations to panic machinery and some cold functions * std dependencies gimli and addr2line are now built with opt-level=s * various panic-related methods and `#[cold]` methods are now marked `#[optimize(size)]` Panics should be cold enough that it doesn't make sense to optimize them for speed. The only tradeoff here is if someone does a lot of backtrace captures (without panics) and printing then the opt-level change might impact their perf. Seems to be the first use of the optimize attribute. Tracking issue rust-lang#54882
This is a tracking issue for the RFC "The optimize attribute" (rust-lang/rfcs#2412).
Steps:
Unresolved questions:
optimize(always)
?optimize(level=x)
?conjunction with the optimization for speed option (e.g.
-Copt-level=s3
could be equivalent to-Copt-level=3
and#[optimize(size)]
on the crate item);#[optimize(speed)]
.unused_attr
approaches right?The text was updated successfully, but these errors were encountered: