Skip to content
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

Specialize query execution for incremental and non-incremental #108062

Merged
merged 1 commit into from
May 16, 2023

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Feb 14, 2023

This specializes query execution for incremental and non-incremental by passing in a separate dyn QueryEngine types, taking advantage of the virtual dispatch to avoid a branch. This ends up duplicating try_execute_query, hopefully the compile time cost of that is relatively low.

This is a performance improvement for the non-incremental path:

BenchmarkBeforeAfter
TimeTime%
🟣 clap:check1.8420s1.8331s -0.48%
🟣 hyper:check0.2652s0.2631s -0.78%
🟣 regex:check1.0161s1.0062s -0.98%
🟣 syn:check1.6408s1.6197s💚 -1.28%
🟣 syntex_syntax:check6.3939s6.3558s -0.60%
Total11.1580s11.0780s -0.72%
Summary1.0000s0.9918s -0.82%

The incremental path is more neutral:

BenchmarkBeforeAfter
TimeTime%
🟣 clap:check:initial2.2210s2.2227s 0.08%
🟣 hyper:check:initial0.3441s0.3443s 0.05%
🟣 regex:check:initial1.2919s1.2877s -0.33%
🟣 syn:check:initial2.0749s2.0721s -0.14%
🟣 syntex_syntax:check:initial7.9266s7.9206s -0.07%
Total13.8585s13.8474s -0.08%
Summary1.0000s0.9992s -0.08%

r? @cjgillot

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 14, 2023
@Noratrieb
Copy link
Member

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 14, 2023
@bors
Copy link
Contributor

bors commented Feb 14, 2023

⌛ Trying commit 8f0b5d5d51d2c7b77c5923545af1c80128ddf69a with merge e327b9e2f1370ae8e47c8de12bdba5ec2acee47c...

@bors
Copy link
Contributor

bors commented Feb 14, 2023

☀️ Try build successful - checks-actions
Build commit: e327b9e2f1370ae8e47c8de12bdba5ec2acee47c (e327b9e2f1370ae8e47c8de12bdba5ec2acee47c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e327b9e2f1370ae8e47c8de12bdba5ec2acee47c): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking 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 @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.6% [0.2%, 3.9%] 54
Regressions ❌
(secondary)
1.1% [0.2%, 3.5%] 75
Improvements ✅
(primary)
-0.6% [-1.1%, -0.3%] 14
Improvements ✅
(secondary)
-0.7% [-1.1%, -0.3%] 27
All ❌✅ (primary) 0.4% [-1.1%, 3.9%] 68

Max RSS (memory usage)

Results

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.

mean range count
Regressions ❌
(primary)
1.2% [1.2%, 1.2%] 1
Regressions ❌
(secondary)
2.7% [1.6%, 4.6%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.6% [-3.6%, -3.6%] 1
All ❌✅ (primary) 1.2% [1.2%, 1.2%] 1

Cycles

Results

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.

mean range count
Regressions ❌
(primary)
2.0% [1.6%, 2.4%] 2
Regressions ❌
(secondary)
1.8% [1.1%, 2.4%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.0% [1.6%, 2.4%] 2

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 15, 2023
@Zoxc
Copy link
Contributor Author

Zoxc commented Feb 16, 2023

This does hurt compile times of rustc_query_impl a bit. Specializing get and ensure modes might be a better tradeoff.

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 19, 2023
@Zoxc Zoxc mentioned this pull request Mar 25, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 29, 2023
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`
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Apr 30, 2023
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`
@Zoxc
Copy link
Contributor Author

Zoxc commented May 14, 2023

This could use another perf run now that #108638 has landed to see what the bootstrap timing impact is.

@cjgillot
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 15, 2023
@bors
Copy link
Contributor

bors commented May 15, 2023

⌛ Trying commit 882a968 with merge 508cb011fb98e4d32bb47430172d91c7d5b08af2...

@bors
Copy link
Contributor

bors commented May 15, 2023

☀️ Try build successful - checks-actions
Build commit: 508cb011fb98e4d32bb47430172d91c7d5b08af2 (508cb011fb98e4d32bb47430172d91c7d5b08af2)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (508cb011fb98e4d32bb47430172d91c7d5b08af2): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking 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
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.6% [-1.2%, -0.4%] 18
Improvements ✅
(secondary)
-0.8% [-1.1%, -0.2%] 30
All ❌✅ (primary) -0.6% [-1.2%, -0.4%] 18

Max RSS (memory usage)

Results

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.2% [2.8%, 3.5%] 2
Improvements ✅
(primary)
-4.4% [-4.9%, -4.1%] 3
Improvements ✅
(secondary)
-4.7% [-4.7%, -4.7%] 1
All ❌✅ (primary) -4.4% [-4.9%, -4.1%] 3

Cycles

Results

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-2.5%, -2.4%] 3
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 643.398s -> 644.756s (0.21%)

@rustbot rustbot removed S-waiting-on-perf Status: Waiting on a perf run to be completed. perf-regression Performance regression. labels May 15, 2023
@Zoxc
Copy link
Contributor Author

Zoxc commented May 15, 2023

Bootstrap timing looks decent enough now. I just need to look into incr-unchanged regressions.

@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented May 16, 2023

📌 Commit 882a968 has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 16, 2023
@bors
Copy link
Contributor

bors commented May 16, 2023

⌛ Testing commit 882a968 with merge b652d9a...

@bors
Copy link
Contributor

bors commented May 16, 2023

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing b652d9a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 16, 2023
@bors bors merged commit b652d9a into rust-lang:master May 16, 2023
@rustbot rustbot added this to the 1.71.0 milestone May 16, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b652d9a): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.3%] 9
Regressions ❌
(secondary)
0.8% [0.2%, 2.9%] 5
Improvements ✅
(primary)
-0.6% [-1.1%, -0.3%] 17
Improvements ✅
(secondary)
-0.8% [-1.2%, -0.2%] 31
All ❌✅ (primary) -0.3% [-1.1%, 0.3%] 26

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

Results

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.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.7% [-0.7%, -0.7%] 1
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 642.522s -> 644.057s (0.24%)

@rustbot rustbot added the perf-regression Performance regression. label May 16, 2023
@pnkfelix
Copy link
Member

the sea of green improvements to scenario=full outweighs the occasional (and minor) red regressions to incr cases.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label May 23, 2023
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 20, 2024
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`
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants