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

Erase query cache values #109333

Merged
merged 5 commits into from
Apr 6, 2023
Merged

Erase query cache values #109333

merged 5 commits into from
Apr 6, 2023

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Mar 19, 2023

This replaces most concrete query values V with MaybeUninit<[u8; { size_of::<V>() }]> without introducing dynamic dispatch like #108638 does. This is split out of #108638 so the performance impact of only this change can be measured.

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 Mar 19, 2023
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Mar 21, 2023

☔ The latest upstream changes (presumably #109092) made this pull request unmergeable. Please resolve the merge conflicts.

@Zoxc Zoxc force-pushed the erase-query-cache-values branch 2 times, most recently from 41cc263 to 8bb1455 Compare March 25, 2023 22:34
@workingjubilee
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 Mar 26, 2023
@bors
Copy link
Contributor

bors commented Mar 26, 2023

⌛ Trying commit 8bb14552a001fe563ad6e3da20fc1b1838a0d6ad with merge 013c87b3813eab23d1ebea1d7cb8aac3624f02a2...

@bors
Copy link
Contributor

bors commented Mar 26, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (013c87b3813eab23d1ebea1d7cb8aac3624f02a2): 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
Regressions ❌
(secondary)
0.5% [0.4%, 0.7%] 6
Improvements ✅
(primary)
-0.5% [-0.6%, -0.4%] 6
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.5% [-0.6%, -0.4%] 6

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)
2.3% [0.9%, 4.3%] 3
Improvements ✅
(primary)
-0.9% [-1.5%, -0.5%] 13
Improvements ✅
(secondary)
-1.5% [-5.3%, -0.4%] 18
All ❌✅ (primary) -0.9% [-1.5%, -0.5%] 13

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)
1.3% [0.9%, 2.0%] 7
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-0.4%, -0.4%] 1
All ❌✅ (primary) - - 0

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Mar 26, 2023
compiler/rustc_middle/src/query/erase.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/query/erase.rs Outdated Show resolved Hide resolved
@@ -1089,7 +1090,7 @@ pub fn encode_query_results<'a, 'tcx, Q>(

// Encode the type check tables with the `SerializedDepNodeIndex`
// as tag.
encoder.encode_tagged(dep_node, value);
encoder.encode_tagged(dep_node, &Q::restore(*value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this deserve an restore_ref(&Erased<T>) -> &T helper?
Can't we use restore directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not safe as alignment can differ.

compiler/rustc_query_impl/src/plumbing.rs Outdated Show resolved Hide resolved
([]) => {{
Some(dep_graph::hash_result)
([][$V:ty]) => {{
Some(|hcx, result| dep_graph::hash_result(hcx, &restore::<$V>(*result)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise restore_ref

compiler/rustc_middle/src/query/erase.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/query/erase.rs Outdated Show resolved Hide resolved
@@ -44,6 +46,14 @@ pub use on_disk_cache::OnDiskCache;
mod profiling_support;
pub use self::profiling_support::alloc_self_profile_query_strings;

trait QueryToConfig<'tcx>: 'tcx {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you document this trait?

@@ -11,7 +11,6 @@ use crate::query::job::QueryLatch;
use crate::query::job::{report_cycle, QueryInfo, QueryJob, QueryJobId, QueryJobInfo};
use crate::query::SerializedDepNodeIndex;
use crate::query::{QueryContext, QueryMap, QuerySideEffects, QueryStackFrame};
use crate::values::Value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trait and its can now be grouped in rustc_middle::query::values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add an impl<T, C> !Value<C> for Erased<T> to avoid jokes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into specialization errors trying to remove the unsafe Value impls in rustc_middle, so I think I'll just leave it in rustc_query_system.

@@ -45,6 +45,12 @@ pub trait QueryConfig<Qcx: QueryContext>: Copy {

fn loadable_from_disk(self, qcx: Qcx, key: &Self::Key, idx: SerializedDepNodeIndex) -> bool;

fn from_cycle_error(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn from_cycle_error(
/// Synthesize a dummy return value to let compilation continue emitting errors.
fn value_from_cycle_error(

@Zoxc
Copy link
Contributor Author

Zoxc commented Mar 26, 2023

This could use another perf run to see if removing the Debug impl for Erased affects performance.

@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 Mar 26, 2023
@bors
Copy link
Contributor

bors commented Mar 26, 2023

⌛ Trying commit 38bc74365eacf98fe04b6332643d436b296f17b4 with merge 6804bca3e0eba91188cf84b898e9ac4805993725...

@bors
Copy link
Contributor

bors commented Mar 26, 2023

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

1 similar comment
@bors
Copy link
Contributor

bors commented Mar 26, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (6804bca3e0eba91188cf84b898e9ac4805993725): 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
Regressions ❌
(secondary)
0.3% [0.1%, 0.4%] 4
Improvements ✅
(primary)
-0.3% [-0.4%, -0.3%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.3% [-0.4%, -0.3%] 4

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% [3.2%, 3.2%] 1
Improvements ✅
(primary)
-1.7% [-3.3%, -0.8%] 62
Improvements ✅
(secondary)
-2.9% [-4.5%, -1.7%] 5
All ❌✅ (primary) -1.7% [-3.3%, -0.8%] 62

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.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
12.5% [11.0%, 13.9%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.6% [2.6%, 2.6%] 1

@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2023
@rust-log-analyzer

This comment has been minimized.

@Zoxc Zoxc force-pushed the erase-query-cache-values branch from 7cb67e5 to 0110073 Compare April 6, 2023 06:35
@Zoxc
Copy link
Contributor Author

Zoxc commented Apr 6, 2023

Rebased.

@cjgillot
Copy link
Contributor

cjgillot commented Apr 6, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Apr 6, 2023

📌 Commit 0110073 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-review Status: Awaiting review from the assignee but also interested parties. labels Apr 6, 2023
@bors
Copy link
Contributor

bors commented Apr 6, 2023

⌛ Testing commit 0110073 with merge f5b8f44...

@bors
Copy link
Contributor

bors commented Apr 6, 2023

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 6, 2023
@bors bors merged commit f5b8f44 into rust-lang:master Apr 6, 2023
@rustbot rustbot added this to the 1.70.0 milestone Apr 6, 2023
@Zoxc Zoxc deleted the erase-query-cache-values branch April 6, 2023 18:50
@bors bors mentioned this pull request Apr 6, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f5b8f44): comparison URL.

Overall result: ❌ regressions - 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.4% [0.2%, 0.6%] 43
Regressions ❌
(secondary)
0.4% [0.3%, 0.7%] 13
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [0.2%, 0.6%] 43

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)
- - 0
Improvements ✅
(primary)
-1.3% [-2.7%, -0.6%] 14
Improvements ✅
(secondary)
-2.7% [-4.9%, -0.8%] 20
All ❌✅ (primary) -1.3% [-2.7%, -0.6%] 14

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.7% [-2.7%, -2.7%] 1
All ❌✅ (primary) - - 0

@nnethercote
Copy link
Contributor

@Zoxc: this ended up regressing much more than the pre-merge runs suggested. I see you tried to improve things in #110057, but this didn't work. What now?

@Zoxc
Copy link
Contributor Author

Zoxc commented Apr 14, 2023

Looking at the non-significant earlier perf results there are some bumps in instructions count when adding the format_value argument to incremental_verify_ich and when fully erasing the value types. The latter would cause inlining differences and is hard to control for. It the may also swing back on further changes. The former is necessary, but it could be a better idea to pass query to it instead. That's something that could be tested post #108638.

I also noticed functions not getting inlined since we use 16 CGUs instead of 1. It would be nice if we had 1 CGU for perf runs.

@rylev
Copy link
Member

rylev commented Apr 19, 2023

@Zoxc (I'm doing perf triage) would it make sense to make an issue for this? It looks like this has a risk of getting forgotten especially if it takes #108638 a while to land.

@Zoxc
Copy link
Contributor Author

Zoxc commented Apr 19, 2023

It's not clear if it will be an improvement and it could easily get lost in the sea of issues instead.

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.

9 participants