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 duplicating code for each query #69808

Merged
merged 9 commits into from
May 2, 2020
Merged

Avoid duplicating code for each query #69808

merged 9 commits into from
May 2, 2020

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Mar 7, 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.

The first part of this PR reduces the amount of code generic on the query,
replacing it by code generic on the key-value types. I can split it out if needed.

In a second part, the non-inlined methods in the QueryAccessors and QueryDescription traits
are made into a virtual dispatch table. This allows to reduce even more the number of generated
functions.

This allows to save 1.5s on check build, and 10% on the size of the librustc.rlib.
(Attributed roughly half and half).
My computer is not good enough to measure properly compiling time.
I have no idea of the effect on performance. A perf run may be required.

cc #65031

@rust-highfive
Copy link
Collaborator

r? @estebank

(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 7, 2020
@jonas-schievink
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Mar 7, 2020

⌛ Trying commit f12bdf2 with merge 576b7b6...

bors added a commit that referenced this pull request Mar 7, 2020
Avoid duplicating code for each query

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.

The first part of this PR reduces the amount of code generic on the query,
replacing it by code generic on the key-value types. I can split it out if needed.

In a second part, the non-inlined methods in the `QueryAccessors` and `QueryDescription` traits
are made into a virtual dispatch table. This allows to reduce even more the number of generated
functions.

This allows to save 1.5s on check build, and 10% on the size of the librustc.rlib.
(Attributed roughly half and half).
My computer is not good enough to measure properly compiling time.
I have no idea of the effect on performance. A perf run may be required.

cc #65031
@bors
Copy link
Contributor

bors commented Mar 7, 2020

☀️ Try build successful - checks-azure
Build commit: 576b7b6 (576b7b6be86f607b43b4009aeab1f6393b7c46e7)

@rust-timer
Copy link
Collaborator

Queued 576b7b6 with parent 823ff8c, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 576b7b6, comparison URL.

@nnethercote
Copy link
Contributor

Causes a slight regression in the compiler's performance, unfortunately.

@Zoxc
Copy link
Contributor

Zoxc commented Mar 12, 2020

This seems to be very similar to my branch here. That branch goes a bit further with the removal of the Q type parameter. It also has some code to erase query value types, but that is quite WIP and blocked on some language features.

This does seem to increase the compiler performance though, not sure if that's just perf noise or due to better instruction cache utilization.

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
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
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 21, 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
@cjgillot
Copy link
Contributor Author

Rebased.

@Zoxc: Is there something I should take from your branch and add here?

@Zoxc
Copy link
Contributor

Zoxc commented Mar 21, 2020

@cjgillot I'd leave that for a future PR.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Mar 21, 2020

⌛ Trying commit 21349c0c7a78f5e13e5156f4f2edb4eb16400093 with merge d5a581b4e2aad68744b0a6138de00c4a572a1b85...

@bors
Copy link
Contributor

bors commented Mar 21, 2020

☀️ Try build successful - checks-azure
Build commit: d5a581b4e2aad68744b0a6138de00c4a572a1b85 (d5a581b4e2aad68744b0a6138de00c4a572a1b85)

@Zoxc
Copy link
Contributor

Zoxc commented Mar 22, 2020

@rust-timer build d5a581b4e2aad68744b0a6138de00c4a572a1b85

@rust-timer
Copy link
Collaborator

Queued d5a581b4e2aad68744b0a6138de00c4a572a1b85 with parent 7900b2b, future comparison URL.

@joelpalmer joelpalmer added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 30, 2020
@joelpalmer joelpalmer removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 9, 2020
@bors
Copy link
Contributor

bors commented May 1, 2020

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

@cjgillot
Copy link
Contributor Author

cjgillot commented May 1, 2020

Rebased.

@@ -645,6 +647,7 @@ where
/// side-effects -- e.g., in order to report errors for erroneous programs.
///
/// Note: The optimization is only available during incr. comp.
#[inline(never)]
Copy link
Member

Choose a reason for hiding this comment

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

why the #[inline(never)] marker here? Did you observe a need for it on some benchmark locally?

Copy link
Member

Choose a reason for hiding this comment

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

(no, your description says your rig is not suitable for local benchmarking, so that cannot be the answer...)

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 don't remember. I can remove it.

@@ -681,7 +684,8 @@ fn ensure_query_impl<CTX, C>(
}
}

fn force_query_impl<C, CTX>(
#[inline(never)]
Copy link
Member

Choose a reason for hiding this comment

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

(same as above, just wondering what prompted this use of #[inline(never)]...)

@pnkfelix
Copy link
Member

pnkfelix commented May 1, 2020

This looks great. I am especially happy with how the commits in this PR were laid out; it made it very easy to review.

@pnkfelix pnkfelix closed this May 1, 2020
@pnkfelix pnkfelix reopened this May 1, 2020
@pnkfelix
Copy link
Member

pnkfelix commented May 1, 2020

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented May 1, 2020

📌 Commit e4976d0 has been approved by pnkfelix

@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 May 1, 2020
@pnkfelix
Copy link
Member

pnkfelix commented May 1, 2020

(tagging as rollup=never since we want to track its performance impact separately from other PR's)

@Dylan-DPC-zz
Copy link

@bors p=1

@bors
Copy link
Contributor

bors commented May 1, 2020

⌛ Testing commit e4976d0 with merge dba944a...

@bors
Copy link
Contributor

bors commented May 2, 2020

☀️ Test successful - checks-azure
Approved by: pnkfelix
Pushing dba944a to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 2, 2020
@bors bors merged commit dba944a into rust-lang:master May 2, 2020
@cjgillot cjgillot deleted the vtbl branch May 2, 2020 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.