-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Constant let binding slower than const #36001
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
Comments
with |
@nagisa shouldn't the array get promoted anyway, so the |
Ok, just checked and a /cc @eddyb & @rust-lang/compiler |
@Aatch The first constant promotion pass has a semantic role (in rvalue promotion), so it has to happen early, before MIR borrow-checking. I believe that we should be able to work with field assignments instead of On the upside, this would work really well with inlining and even arbitrary control-flow (we can extract a deterministic subset of a function and evaluate it speculatively with miri). |
@eddyb it might be worthwhile to just have a pass that promotes in pretty much just this case. I can see large arrays being a common cause of either stack exhaustion or performance issues compared to aggregates. Even if it's replaced by a more sophisticated analysis + transformation, it'd be a good short-term gain. That said, it seems that this issue isn't MIR-specific, as the old backend doesn't promote it either, so maybe it's not worth the effort on a short-term fix. |
@Aatch Sorry, I used "aggregate" in the MIR sense, which includes arrays. |
@eddyb sure, but only when you need a copy, which, like in this case, you might not. The fact that you can change the |
Can we do this in LLVM? |
@pcwalton I know clang doesn't, but you would have to ask someone from LLVM to know why. |
Seems pretty unfortunate that this happens. It would be nice to get an answer to @pcwalton's question. We should also probably close #45126 as a dupe of this one. I wonder if such Cc @rust-lang/wg-codegen |
Well. We now offer considerable However! |
One thing I seem to not have mentioned is making sure you have In fact, I think that even |
Hello.
I am currently optimizing my
des
crate and I found out that using alet
statement can be significantly slower than using aconst
statement.For instance, when I run
cargo bench
with theconst
declaration here, I get:If I replace this
const
by alet
, the performance is not as good:On another benchmark, I think it was 4 times slower with
let
.I expected to have the same performance with a constant
let
and aconst
.Instead, the
let
declaration is slower than aconst
.Meta
rustc --version --verbose
:Thanks to fix this issue.
The text was updated successfully, but these errors were encountered: