-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Performance regression in 1.84 for inline-able function in closure #137273
Comments
cc @RalfJung IIUC the code that regresses performance is: // #[inline(never)]
pub fn sum_all(v: &[i32]) -> i32 {
v.iter().fold(0i32, |a, b| curried_add(a)(*b))
}
fn curried_add(a: i32) -> Box<dyn Fn(i32) -> i32> {
Box::new(move |b| a + b)
} |
I guess it could pass some threshold in some heuristic somewhere? That can happen with any tiny change though. It is very odd though that adding Note that the inlining handling for |
That PR only changes very few functions that are not already |
Yes, [profile.bench]
codegen-units = 1 I don't think a bisection is informative here, all that PR did was probably perturb CGU partitioning to cause the bad partitioning. This kind of behavior smells like IPSCCP https://llvm.org/docs/Passes.html#ipsccp-interprocedural-sparse-conditional-constant-propagation |
Also, it looks like adding |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-medium |
It seems that |
Closures should always get So normally CGU partitioning doesn't block inlining of a closure. Perhaps the |
Code
I tried this code:
I expected to see this happen: ~26 µs reported by
cargo bench
Instead, this happened: ~1.4 ms reported by
cargo bench
Version it worked on
It most recently worked on: 1.83.0
Version with regression
rustc --version --verbose
:Backtrace
no compiler crash
#inline
If I uncomment
#[inline(never)]
line, the performance is back to normal under 1.84.bisecting output
searched nightlies: from nightly-2024-10-13 to nightly-2024-11-22
regressed nightly: nightly-2024-11-04
searched commit range: b3f75cc...b8c8287
regressed commit: e3a918e
bisected with cargo-bisect-rustc v0.6.9
Host triple: aarch64-apple-darwin
Reproduce with:
e3a918e comes from #132542
The text was updated successfully, but these errors were encountered: