-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Migrate compiler's &Option<T>
into Option<&T>
#130963
base: master
Are you sure you want to change the base?
Conversation
rustbot has assigned @petrochenkov. Use |
Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 |
&Option<T>
into Option<&T>
&Option<T>
into Option<&T>
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Migrate compiler's `&Option<T>` into `Option<&T>` Similar to rust-lang#130962 but for the compiler. Trying out my new lint rust-lang/rust-clippy#13336 - according to the [video](https://www.youtube.com/watch?v=6c7pZYP_iIE), this could lead to some performance and memory optimizations.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (aabe0bd): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary 2.4%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary -2.7%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 774.209s -> 771.637s (-0.33%) |
It seems some performance benchmarks are positive, while others are unchanged. While perf was not the primary reason for this PR, it could be a good bonus. I tried running this benchmark (assuming I got it done right), it shows about 11% difference. If I change use criterion::{criterion_group, criterion_main, Criterion};
#[inline(never)]
pub fn do_ref(val: &Option<Vec<usize>>) -> usize {
match val {
None => 42,
Some(val) => val.iter().sum(),
}
}
#[inline(never)]
pub fn do_as_ref(val: Option<&Vec<usize>>) -> usize {
match val {
None => 42,
Some(val) => val.iter().sum(),
}
}
fn criterion_benchmark(c: &mut Criterion) {
let data: Option<Vec<usize>> = Some(vec![0; 2]);
c.bench_function("ref", |b| b.iter(|| do_ref(&data)));
c.bench_function("as_ref", |b| b.iter(|| do_as_ref(data.as_ref())));
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches); |
I don't think it always makes sense. For example, in AST "qualified path" nodes are always stored as I suggest the following policy: if the function is not public to other crates and all its calls require @rustbot author |
Thanks for the feedback. My only concern with this is that we will miss some performance optimizations. The |
☔ The latest upstream changes (presumably #132250) made this pull request unmergeable. Please resolve the merge conflicts. |
@nyurik any updates on this? thanks |
This comment has been minimized.
This comment has been minimized.
@Dylan-DPC thx for the heads up. I updated the PR, but I think my comment is still relevant. |
☔ The latest upstream changes (presumably #129514) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #134395) made this pull request unmergeable. Please resolve the merge conflicts. |
Similar to #130962 but for the compiler.
Trying out my new lint rust-lang/rust-clippy#13336 - according to the video, this could lead to some performance and memory optimizations.
Basic thoughts expressed in the video that seem to make sense:
&Option<T>
in an API breaks encapsulation:&Option<T>
points to memory that haspresence
flag + value, whereasOption<&T>
by specification is always optimized to a single pointer.