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

Speed up compilation of type-system-chess #114611

Merged
merged 4 commits into from
Aug 18, 2023

Conversation

nnethercote
Copy link
Contributor

type-system-chess is an unusual program that implements a compile-time chess position solver in the trait system(!) This PR is about making it compile faster.

r? @ghost

@rustbot rustbot added 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 8, 2023
@nnethercote
Copy link
Contributor Author

These lines are the cause. They perform deduplication on obligation vectors. The vectors get enormous, the biggest are over 250,000 elements. The deduplication of these huge vectors is effective, typically removing more than half of the elements.

@nnethercote
Copy link
Contributor Author

@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 Aug 8, 2023
@bors
Copy link
Contributor

bors commented Aug 8, 2023

⌛ Trying commit 3c59e126ee8f731fb518af16ecafcb0746ae9431 with merge 78d71d60405cf6176f462492f3acea7134e818eb...

@bors
Copy link
Contributor

bors commented Aug 8, 2023

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

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (78d71d60405cf6176f462492f3acea7134e818eb): 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.4% [0.4%, 0.4%] 1
Regressions ❌
(secondary)
0.5% [0.5%, 0.5%] 1
Improvements ✅
(primary)
-1.3% [-1.3%, -1.3%] 1
Improvements ✅
(secondary)
-2.3% [-4.5%, -0.9%] 26
All ❌✅ (primary) -0.5% [-1.3%, 0.4%] 2

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)
2.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
2.7% [1.6%, 3.4%] 3
Improvements ✅
(primary)
-1.3% [-1.3%, -1.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.7% [-1.3%, 2.6%] 2

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

Binary size

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

Bootstrap: 631.452s -> 631.003s (-0.07%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Aug 9, 2023
This gives massive (~7x) compile time and memory usage reductions for
the trait system stress test in
rust-lang/rustc-perf#1680.
@nnethercote
Copy link
Contributor Author

Perf results look good, various small improvements in secondary benchmarks. The real driver was the type-system-chess program I mentioned above, where the walltime and max-rss changes were both about -85% when I measured them locally.

r? @compiler-errors

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Aug 17, 2023

📌 Commit 698f0e3 has been approved by compiler-errors

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 Aug 17, 2023
@bors
Copy link
Contributor

bors commented Aug 18, 2023

⌛ Testing commit 698f0e3 with merge a1e1dba...

@bors
Copy link
Contributor

bors commented Aug 18, 2023

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing a1e1dba to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 18, 2023
@bors bors merged commit a1e1dba into rust-lang:master Aug 18, 2023
12 checks passed
@rustbot rustbot added this to the 1.73.0 milestone Aug 18, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a1e1dba): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -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)
-1.7% [-1.7%, -1.7%] 1
Improvements ✅
(secondary)
-2.2% [-4.2%, -0.7%] 28
All ❌✅ (primary) -1.7% [-1.7%, -1.7%] 1

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.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.3% [-3.5%, -1.2%] 2
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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 2
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 633.189s -> 633.173s (-0.00%)
Artifact size: 347.08 MiB -> 347.02 MiB (-0.02%)

@rustbot rustbot removed the perf-regression Performance regression. label Aug 18, 2023
@nnethercote nnethercote deleted the type-system-chess branch August 20, 2023 23:22
@zesterer
Copy link
Contributor

Is this likely to have a meaningful impact on other crates that produce a lot of trait obligations such as chumsky?

@nnethercote
Copy link
Contributor Author

type-system-chess is an extreme outlier. I doubt this will have any effect on "real world" crates beyond perhaps a couple of percent. But you'd have to measure to be sure (nightly vs release should suffice).

nnethercote added a commit to nnethercote/rust that referenced this pull request Oct 17, 2023
Commit 8378487 from rust-lang#114611 changed the location of an obligation
deduplication step in `opt_normalize_projection_type`. This meant that
deduplication stopped happening on one path where it was still
necessary, causing a couple of drastic performance regressions.

This commit moves the deduplication back to the old location. The good
news is that rust-lang#114611 had four commits and 8378487 was of minimal
importance, so the perf benefits from that PR remain.

Fixes rust-lang#116780, rust-lang#116797.
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 17, 2023
…piler-errors

Fix a performance regression in obligation deduplication.

Commit 8378487 from rust-lang#114611 changed the location of an obligation deduplication step in `opt_normalize_projection_type`. This meant that deduplication stopped happening on one path where it was still necessary, causing a couple of drastic performance regressions.

This commit moves the deduplication back to the old location. The good news is that rust-lang#114611 had four commits and 8378487 was of minimal importance, so the perf benefits from that PR remain.

Fixes rust-lang#116780, rust-lang#116797.

r? `@compiler-errors`
cuviper pushed a commit to cuviper/rust that referenced this pull request Oct 21, 2023
Commit 8378487 from rust-lang#114611 changed the location of an obligation
deduplication step in `opt_normalize_projection_type`. This meant that
deduplication stopped happening on one path where it was still
necessary, causing a couple of drastic performance regressions.

This commit moves the deduplication back to the old location. The good
news is that rust-lang#114611 had four commits and 8378487 was of minimal
importance, so the perf benefits from that PR remain.

Fixes rust-lang#116780, rust-lang#116797.

(cherry picked from commit 91f2fbc)
xobs pushed a commit to betrusted-io/rust that referenced this pull request Nov 7, 2023
Commit 8378487 from rust-lang#114611 changed the location of an obligation
deduplication step in `opt_normalize_projection_type`. This meant that
deduplication stopped happening on one path where it was still
necessary, causing a couple of drastic performance regressions.

This commit moves the deduplication back to the old location. The good
news is that rust-lang#114611 had four commits and 8378487 was of minimal
importance, so the perf benefits from that PR remain.

Fixes rust-lang#116780, rust-lang#116797.

(cherry picked from commit 91f2fbc)
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. 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.

None yet

6 participants