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

Extract suitable code from rustc_query_impl into a new crate rustc_query_misc #115118

Closed
wants to merge 1 commit into from

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Aug 22, 2023

This extracts code from rustc_query_impl into a new crate rustc_query_misc in order to reduce the compile time of rustc_query_impl. The compile time of the new crate is roughly 60% of the remaining rustc_query_impl .

I've picked code which should not impact performance or result in duplicate generic code generation. Encoding and decoding of query results and profiling handling is moved along with some other minor methods which use dynamic dispatch.

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 Aug 22, 2023
@rustbot
Copy link
Collaborator

rustbot commented Aug 22, 2023

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rust-log-analyzer

This comment has been minimized.

@Zoxc Zoxc force-pushed the rustc-query-encode branch from 0f950d4 to f53c0ee Compare August 22, 2023 22:33
@cjgillot
Copy link
Contributor

I'm not sure I understand the benefit. This crate is still on the critical path middle -> query_misc -> query_impl, so at worst we could lose some codegen parallelism.

@bjorn3
Copy link
Member

bjorn3 commented Aug 23, 2023

Thanks to build pipelining cargo can invoke rustc for a dependent crate while dependencies are still busy with codegen. Only crate metadata writing needs to have finished.

@Zoxc
Copy link
Contributor Author

Zoxc commented Aug 23, 2023

It's a benefit when compiling with codegen-units=1 since rustc_query_impl and rustc_query_misc can each get a core for code generation instead of rustc_query_impl being stuck on one. I use that configuration locally for performance benchmarks and CI should switch to that soon as it compiles faster and results in higher code quality.

@bors
Copy link
Contributor

bors commented Aug 28, 2023

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

@Zoxc Zoxc force-pushed the rustc-query-encode branch from f53c0ee to 6ce11f8 Compare August 29, 2023 05:45
@cjgillot
Copy link
Contributor

cjgillot commented Sep 3, 2023

It's a benefit when compiling with codegen-units=1 since rustc_query_impl and rustc_query_misc can each get a core for code generation instead of rustc_query_impl being stuck on one. I use that configuration locally for performance benchmarks and CI should switch to that soon as it compiles faster and results in higher code quality.

So we split the crate in 2 codegen units, to counteract the fact we ask for only 1?

The split does not follow a functional separation of the crate. The large macro is still there, structured the same way. How should we chose in which crate code goes?

Is there a way to get rid of the dependency between query_misc and query_impl?

@Zoxc
Copy link
Contributor Author

Zoxc commented Sep 3, 2023

So we split the crate in 2 codegen units, to counteract the fact we ask for only 1?

Basically, but we can do it without a performance hit, unlike the automatic partitioning.

The split does not follow a functional separation of the crate. The large macro is still there, structured the same way. How should we chose in which crate code goes?

In general, hot direct calls stays in the same crate, while cold or indirect calls can cross crate boundaries.

Is there a way to get rid of the dependency between query_misc and query_impl?

Yes, but it's not very beneficial as they mostly spend their time in code generation. It's also would require another copy of the macro mentioned.

@bors
Copy link
Contributor

bors commented Sep 3, 2023

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

@Zoxc Zoxc force-pushed the rustc-query-encode branch from 6ce11f8 to bb1d854 Compare September 4, 2023 20:42
@Zoxc
Copy link
Contributor Author

Zoxc commented Sep 9, 2023

Here's a link to the new compilation timings. rustc_middle is back on top as the biggest crate. rustc_borrowck is the new tail.

@bors
Copy link
Contributor

bors commented Sep 13, 2023

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

@Zoxc Zoxc force-pushed the rustc-query-encode branch from bb1d854 to 7daca2c Compare September 14, 2023 09:26
@bors
Copy link
Contributor

bors commented Sep 22, 2023

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

@Zoxc Zoxc force-pushed the rustc-query-encode branch from 7daca2c to c9ce621 Compare September 22, 2023 20:33
@wesleywiser
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 Oct 5, 2023
@bors
Copy link
Contributor

bors commented Oct 5, 2023

⌛ Trying commit c9ce621 with merge 3d352fd...

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 5, 2023
Extract suitable code from rustc_query_impl into a new crate rustc_query_misc

This extracts code from `rustc_query_impl` into a new crate `rustc_query_misc` in order to reduce the compile time of `rustc_query_impl`. The compile time of the new crate is roughly 60% of the remaining `rustc_query_impl` .

I've picked code which should not impact performance or result in duplicate generic code generation. Encoding and decoding of query results and profiling handling is moved along with some other minor methods which use dynamic dispatch.

r? `@cjgillot`
@cjgillot
Copy link
Contributor

cjgillot commented Oct 5, 2023

Making my review in #115118 (comment) more explicit.

I think this PR introduces complexity with no reason beyond bootstrap time.
The query system is already very complex. Splitting into an additional crate should be justified by a reduction in that complexity.

I would accept a PR splitting rustc_query_impl along logical / API boundaries.
Even better, moving code between rustc_query_system and rustc_query_impl to help modularisation and decoupling.

@bors
Copy link
Contributor

bors commented Oct 5, 2023

☀️ Try build successful - checks-actions
Build commit: 3d352fd (3d352fd278737661390c7291be0afe22e8971a0c)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3d352fd): comparison URL.

Overall result: ❌ regressions - 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)
1.5% [0.2%, 7.3%] 21
Regressions ❌
(secondary)
2.1% [0.1%, 6.3%] 73
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.5% [0.2%, 7.3%] 21

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)
5.6% [5.6%, 5.6%] 1
Improvements ✅
(primary)
-3.1% [-3.1%, -3.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.1% [-3.1%, -3.1%] 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)
4.8% [0.7%, 8.4%] 5
Regressions ❌
(secondary)
3.0% [1.6%, 4.8%] 27
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.8% [0.7%, 8.4%] 5

Binary size

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

Bootstrap: 621.055s -> 622.704s (0.27%)
Artifact size: 271.92 MiB -> 272.25 MiB (0.12%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Oct 5, 2023
@apiraino
Copy link
Contributor

Flipping the review switch to the author, I think there are some design questions at this comment on how to proceed.

@rustbot author

@rustbot rustbot 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 Nov 21, 2023
@JohnCSimon
Copy link
Member

Ping from triage:
@Zoxc - can you please address the questions form @apiraino ? Thank you.

@Zoxc Zoxc closed this Feb 15, 2024
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) perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

10 participants