-
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
Move query accessor code into functions #107802
Conversation
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 1fb91b54f117c61f166856ecaf0caca83f84bd03 with merge 203f4baf05d15e06f81a0776f7b923a3f6a84c41... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (203f4baf05d15e06f81a0776f7b923a3f6a84c41): comparison URL. Overall result: ❌✅ regressions and improvements - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
|
Both benchmarks and bootstrap timing show a regression. Do you have an idea why? How can this be avoided? |
There's a 0.28% increase in code size which is likely LLVM inlining more and regressing the compile time of the rustc crates. The |
} | ||
|
||
#[inline(always)] | ||
fn query_ensure<'tcx, Cache, K>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be merged with query_get_at
by adding a QueryMode
parameter and returning an Option
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was a regression:
Benchmark | Before | After | |
Time | Time | % | |
🟣 clap:check | 1.7607s | 1.7700s | 0.52% |
🟣 hyper:check | 0.2565s | 0.2576s | 0.44% |
🟣 regex:check | 0.9807s | 0.9862s | 0.56% |
🟣 syn:check | 1.5808s | 1.5889s | 0.51% |
🟣 syntex_syntax:check | 6.1378s | 6.1567s | 0.31% |
Total | 10.7165s | 10.7594s | 0.40% |
Summary | 1.0000s | 1.0047s | 0.47% |
#[inline(always)] | ||
fn query_get_at<'tcx, Cache, K>( | ||
tcx: TyCtxt<'tcx>, | ||
execute_query: fn( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regression probably comes from here: an indirect call (fn pointer) to an indirect call (dyn QueryEngine
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only 1 indirect call, same as before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you're right. LLVM will inline it anyway though as query_get_at
is #[inline(always)]
so it will discover the function it points to.
Cache::Stored: Copy, | ||
Cache: QueryCache, | ||
{ | ||
let key = key.into_query_param(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this to the caller will make query_get_at
a bit less generic, hopefully improving compile time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was performance neutral and rustc_driver
size increased by 0.03%, which is not a good sign for compile time.
Benchmark | Before | After | |
Time | Time | % | |
🟣 clap:check | 1.7610s | 1.7607s | -0.02% |
🟣 hyper:check | 0.2569s | 0.2570s | 0.07% |
🟣 regex:check | 0.9808s | 0.9815s | 0.07% |
🟣 syn:check | 1.5819s | 1.5814s | -0.03% |
🟣 syntex_syntax:check | 6.1439s | 6.1434s | -0.01% |
Total | 10.7246s | 10.7241s | -0.00% |
Summary | 1.0000s | 1.0002s | 0.02% |
I've pushed it so we can see what perf says.
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit e046b4ca1ef602fd8379bb93a75f7864fb297400 with merge 8bdd2e2179ccbdd8546274274ab39ff27d50aef2... |
☀️ Try build successful - checks-actions |
1 similar comment
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (8bdd2e2179ccbdd8546274274ab39ff27d50aef2): comparison URL. Overall result: ❌✅ regressions and improvements - 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. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResultsThis 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.
|
I changed the code to use
The overall change to this PR seems to improve
|
☔ The latest upstream changes (presumably #108820) made this pull request unmergeable. Please resolve the merge conflicts. |
Remove `QueryEngine` trait This removes the `QueryEngine` trait and `Queries` from `rustc_query_impl` and replaced them with function pointers and fields in `QuerySystem`. As a side effect `OnDiskCache` is moved back into `rustc_middle` and the `OnDiskCache` trait is also removed. This has a couple of benefits. - `TyCtxt` is used in the query system instead of the removed `QueryCtxt` which is larger. - Function pointers are more flexible to work with. A variant of rust-lang#107802 is included which avoids the double indirection. For rust-lang#108938 we can name entry point `__rust_end_short_backtrace` to avoid some overhead. For rust-lang#108062 it avoids the duplicate `QueryEngine` structs. - `QueryContext` now implements `DepContext` which avoids many `dep_context()` calls in `rustc_query_system`. - The `rustc_driver` size is reduced by 0.33%, hopefully that means some bootstrap improvements. - This avoids the unsafe code around the `QueryEngine` trait. r? `@cjgillot`
This was mostly merged as part of #109611. The remaining attributes could use a perf run. |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit b6720ad with merge 2aa83d2eb45fdf777462706ce8ac5e6e0407f4a4... |
☀️ Try build successful - checks-actions |
1 similar comment
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (2aa83d2eb45fdf777462706ce8ac5e6e0407f4a4): comparison URL. Overall result: ✅ improvements - 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 is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
|
r=me with PR title updated |
This no longer seems to be an improvement locally and the bootstrap cost is quite high, so I think I'll close this for now.
|
Remove `QueryEngine` trait This removes the `QueryEngine` trait and `Queries` from `rustc_query_impl` and replaced them with function pointers and fields in `QuerySystem`. As a side effect `OnDiskCache` is moved back into `rustc_middle` and the `OnDiskCache` trait is also removed. This has a couple of benefits. - `TyCtxt` is used in the query system instead of the removed `QueryCtxt` which is larger. - Function pointers are more flexible to work with. A variant of rust-lang/rust#107802 is included which avoids the double indirection. For rust-lang/rust#108938 we can name entry point `__rust_end_short_backtrace` to avoid some overhead. For rust-lang/rust#108062 it avoids the duplicate `QueryEngine` structs. - `QueryContext` now implements `DepContext` which avoids many `dep_context()` calls in `rustc_query_system`. - The `rustc_driver` size is reduced by 0.33%, hopefully that means some bootstrap improvements. - This avoids the unsafe code around the `QueryEngine` trait. r? `@cjgillot`
Remove `QueryEngine` trait This removes the `QueryEngine` trait and `Queries` from `rustc_query_impl` and replaced them with function pointers and fields in `QuerySystem`. As a side effect `OnDiskCache` is moved back into `rustc_middle` and the `OnDiskCache` trait is also removed. This has a couple of benefits. - `TyCtxt` is used in the query system instead of the removed `QueryCtxt` which is larger. - Function pointers are more flexible to work with. A variant of rust-lang/rust#107802 is included which avoids the double indirection. For rust-lang/rust#108938 we can name entry point `__rust_end_short_backtrace` to avoid some overhead. For rust-lang/rust#108062 it avoids the duplicate `QueryEngine` structs. - `QueryContext` now implements `DepContext` which avoids many `dep_context()` calls in `rustc_query_system`. - The `rustc_driver` size is reduced by 0.33%, hopefully that means some bootstrap improvements. - This avoids the unsafe code around the `QueryEngine` trait. r? `@cjgillot`
Remove `QueryEngine` trait This removes the `QueryEngine` trait and `Queries` from `rustc_query_impl` and replaced them with function pointers and fields in `QuerySystem`. As a side effect `OnDiskCache` is moved back into `rustc_middle` and the `OnDiskCache` trait is also removed. This has a couple of benefits. - `TyCtxt` is used in the query system instead of the removed `QueryCtxt` which is larger. - Function pointers are more flexible to work with. A variant of rust-lang/rust#107802 is included which avoids the double indirection. For rust-lang/rust#108938 we can name entry point `__rust_end_short_backtrace` to avoid some overhead. For rust-lang/rust#108062 it avoids the duplicate `QueryEngine` structs. - `QueryContext` now implements `DepContext` which avoids many `dep_context()` calls in `rustc_query_system`. - The `rustc_driver` size is reduced by 0.33%, hopefully that means some bootstrap improvements. - This avoids the unsafe code around the `QueryEngine` trait. r? `@cjgillot`
This reduces the amount of code generated by the macros, which I think is the last item on #96524.
It also improves performance.
r? @cjgillot