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

Avoid query type in generics #69910

Merged
merged 17 commits into from
Mar 21, 2020
Merged

Avoid query type in generics #69910

merged 17 commits into from
Mar 21, 2020

Conversation

cjgillot
Copy link
Contributor

There are at the moment roughly 170 queries in librustc.
The way ty::query is structured, a lot of code is duplicated for each query.
I suspect this to be responsible for a part of librustc'c compile time.

This PR reduces the amount of code generic on the query,
replacing it by code generic on the key-value types.

This is split out of #69808,
and should not contain the perf regression.

cc #65031

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 11, 2020
@Centril
Copy link
Contributor

Centril commented Mar 11, 2020

r? @Zoxc

@Zoxc
Copy link
Contributor

Zoxc commented Mar 11, 2020

I'm not sure how many unique key / value pairs we have for queries, if that isn't much lower than the total query count, this change isn't too impactful.

@cjgillot
Copy link
Contributor Author

As a crude measurement, the number of instances of alloc_self_profile_query_strings_for_query_cache in the rlib goes from 201 to 148. QueryState::iter_results and <DefaultCache as QueryCache>::iter are called several times with closures, so go from 802 to 590 instances each.

@Zoxc
Copy link
Contributor

Zoxc commented Mar 12, 2020

That suggests that 26% of query key / value pairs are duplicates, so this is probably worthwhile.

@Zoxc
Copy link
Contributor

Zoxc commented Mar 13, 2020

Why is my Erase trait added here?

@cjgillot
Copy link
Contributor Author

I was experimenting with it yesterday, and somehow it ended up on the wrong branch. Sorry.

@Zoxc
Copy link
Contributor

Zoxc commented Mar 13, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Mar 13, 2020

⌛ Trying commit 2bf1353 with merge 4adbc79...

bors added a commit that referenced this pull request Mar 13, 2020
Avoid query type in generics

There are at the moment roughly 170 queries in librustc.
The way ty::query is structured, a lot of code is duplicated for each query.
I suspect this to be responsible for a part of librustc'c compile time.

This PR reduces the amount of code generic on the query,
replacing it by code generic on the key-value types.

This is split out of #69808,
and should not contain the perf regression.

cc #65031
@bors
Copy link
Contributor

bors commented Mar 13, 2020

☀️ Try build successful - checks-azure
Build commit: 4adbc79 (4adbc79bec9c18982551d4c0a11ed917425171bb)

@rust-timer
Copy link
Collaborator

Queued 4adbc79 with parent 54b7d21, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 4adbc79, comparison URL.

pub(super) fn try_collect_active_jobs(
&self,
kind: DepKind,
make_query: impl Fn(C::Key) -> Query<'tcx> + Copy,
Copy link
Contributor

Choose a reason for hiding this comment

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

You could use &dyn for make_query here.

@Zoxc
Copy link
Contributor

Zoxc commented Mar 15, 2020

There are at the moment roughly 170 queries in librustc.
The way ty::query is structured, a lot of code is duplicated for each query.
I suspect this to be responsible for a part of librustc'c compile time.

I measured the compilation impact of the query system to be 25% of librustc's compile time 3. February.

@bors
Copy link
Contributor

bors commented Mar 15, 2020

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

@cjgillot
Copy link
Contributor Author

Rebased.

@Zoxc
Copy link
Contributor

Zoxc commented Mar 17, 2020

I'd leave out the Bundle key commits since they add additional clone calls, otherwise this looks good.

@cjgillot
Copy link
Contributor Author

Done.

@Zoxc
Copy link
Contributor

Zoxc commented Mar 17, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Mar 17, 2020

📌 Commit 8aa1328 has been approved by Zoxc

@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 Mar 17, 2020
Centril added a commit to Centril/rust that referenced this pull request Mar 19, 2020
Avoid query type in generics

There are at the moment roughly 170 queries in librustc.
The way ty::query is structured, a lot of code is duplicated for each query.
I suspect this to be responsible for a part of librustc'c compile time.

This PR reduces the amount of code generic on the query,
replacing it by code generic on the key-value types.

This is split out of rust-lang#69808,
and should not contain the perf regression.

cc rust-lang#65031
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 20, 2020
Avoid query type in generics

There are at the moment roughly 170 queries in librustc.
The way ty::query is structured, a lot of code is duplicated for each query.
I suspect this to be responsible for a part of librustc'c compile time.

This PR reduces the amount of code generic on the query,
replacing it by code generic on the key-value types.

This is split out of rust-lang#69808,
and should not contain the perf regression.

cc rust-lang#65031
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 21, 2020
Rollup of 6 pull requests

Successful merges:

 - rust-lang#69497 (Don't unwind when hitting the macro expansion recursion limit)
 - rust-lang#69901 (add #[rustc_layout(debug)])
 - rust-lang#69910 (Avoid query type in generics)
 - rust-lang#69955 (Fix abort-on-eprintln during process shutdown)
 - rust-lang#70032 (put type params in front of const params in generics_of)
 - rust-lang#70119 (rustc: use LocalDefId instead of DefId in TypeckTables.)

Failed merges:

r? @ghost
@bors bors merged commit 8deeac1 into rust-lang:master Mar 21, 2020
@cjgillot cjgillot deleted the polym branch March 21, 2020 17:52
&self,
state: &'tcx QueryState<'tcx, Q>,
state: &'tcx QueryState<'tcx, Self>,
get_cache: GetCache,
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that you connected up the types, you should be able to just get rid of get_cache: GetCache.

impl<'tcx, C: QueryCache> QueryState<'tcx, C> {
pub(super) fn get_lookup<K2: Hash>(
&'tcx self,
key: &K2,
Copy link
Contributor

Choose a reason for hiding this comment

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

K2 can now be C::Key.

bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 27, 2020
Move the query system to a dedicated crate

The query system `rustc::ty::query` is split out into the `rustc_query_system` crate.

Some commits are unformatted, to ease rebasing.

Based on rust-lang#67761 and rust-lang#69910.

r? @Zoxc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants