Skip to content

[perf] GenericArgs-related: Change asserts to debug asserts & use more slice interning over iterable interning #142289

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

Merged
merged 2 commits into from
Jun 14, 2025

Conversation

fmease
Copy link
Member

@fmease fmease commented Jun 10, 2025

  1. The 1st commit yields the following perf gains: #142289 (comment).
  2. The 2nd commit might also have a minor positive perf impact, however that one wasn't tested in isolation.

For reference, the initial approach c7e6acc (results: #142289 (comment)) had a lot more changes (apart from what's now contained in commit 1 and 2) which seemed to be perf irrelevant (cf. the partial countercheck in 6f82bf1 (results: #142289 (comment)).

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 10, 2025
@fmease fmease added the S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. label Jun 10, 2025
@fmease fmease force-pushed the maybe-perf-gen-args branch from c9e7983 to e2e88ca Compare June 10, 2025 10:10
@fmease fmease added the rla-silenced Silences rust-log-analyzer postings to the PR it's added on. label Jun 10, 2025
@fmease fmease force-pushed the maybe-perf-gen-args branch from e2e88ca to 5ed5135 Compare June 10, 2025 10:31
@fmease fmease changed the title [perf] Tweak GenericArgs::truncate_to and AliasTerm::own_args [perf] Tweak GenericArgs-related functions Jun 10, 2025
@fmease
Copy link
Member Author

fmease commented Jun 10, 2025

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jun 10, 2025

⌛ Trying commit 5ed5135 with merge c7e6acc

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 10, 2025
[perf] Tweak `GenericArgs`-related functions
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 10, 2025
@rust-bors
Copy link

rust-bors bot commented Jun 10, 2025

☀️ Try build successful (CI)
Build commit: c7e6acc (c7e6accd79d91fe5dec01a81499a08f9db280440)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c7e6acc): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
-0.2% [-0.4%, -0.1%] 14
Improvements ✅
(secondary)
-1.7% [-5.6%, -0.2%] 11
All ❌✅ (primary) -0.2% [-0.4%, -0.1%] 14

Max RSS (memory usage)

Results (primary -9.0%, secondary 2.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.7% [2.7%, 2.7%] 1
Improvements ✅
(primary)
-9.0% [-9.0%, -9.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -9.0% [-9.0%, -9.0%] 1

Cycles

Results (secondary -1.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.8% [-3.0%, -2.6%] 2
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 753.145s -> 754.777s (0.22%)
Artifact size: 372.18 MiB -> 372.15 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 11, 2025
@fmease fmease force-pushed the maybe-perf-gen-args branch 2 times, most recently from 196f52a to 642bb6d Compare June 11, 2025 11:58
@fmease
Copy link
Member Author

fmease commented Jun 11, 2025

I want to check what happens if I only do the assert_matchesdebug_assert_matches change since I can't quite tell from the self-profile and the query trace if that's the actual and only reason for the perf improvement we're seeing.

@bors2 try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jun 11, 2025

⌛ Trying commit 642bb6d with merge ce5fbc7

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 11, 2025
[perf] Tweak `GenericArgs`-related functions

Result: #142289 (comment)
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 11, 2025
@fmease
Copy link
Member Author

fmease commented Jun 11, 2025

Wait, I want to set parent=last

@bors2 try cancel

@rust-bors
Copy link

rust-bors bot commented Jun 11, 2025

Try build cancelled. Cancelled workflows:

@fmease
Copy link
Member Author

fmease commented Jun 11, 2025

@bors2 try parent=40daf23eeb711dadf140b2536e67e3ff4c999196 @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Jun 11, 2025

⌛ Trying commit 642bb6d with merge 7c7eef3

To cancel the try build, run the command @bors2 try cancel.

rust-bors bot added a commit that referenced this pull request Jun 11, 2025
[perf] Tweak `GenericArgs`-related functions

Result: #142289 (comment)
@rust-bors
Copy link

rust-bors bot commented Jun 11, 2025

☀️ Try build successful (CI)
Build commit: 7c7eef3 (7c7eef3fba42244270022433fc859ce602611e59, parent: 40daf23eeb711dadf140b2536e67e3ff4c999196)

@fmease fmease force-pushed the maybe-perf-gen-args branch from e5e876a to 3a31f62 Compare June 12, 2025 23:16
@fmease fmease removed S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. rla-silenced Silences rust-log-analyzer postings to the PR it's added on. labels Jun 12, 2025
@fmease fmease changed the title [perf] Tweak GenericArgs-related functions [perf] trait_ref_own_args: Change assert to debug assert and use more slice interning over iterable interning Jun 12, 2025
Comment on lines -279 to -280
let method_args =
tcx.mk_args_from_iter(trait_args.iter().skip(callee_generics.parent_count));
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a drive-by change, definitely not relevant or hot.

Comment on lines +271 to +273
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
let trait_def_id = self.parent(def_id);
assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
Copy link
Member Author

Choose a reason for hiding this comment

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

The main and most relevant positive perf impact comes from changing these asserts to debug ones. Results: #142289 (comment).

@@ -588,7 +588,7 @@ impl<'tcx> GenericArgs<'tcx> {
}

pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> GenericArgsRef<'tcx> {
tcx.mk_args_from_iter(self.iter().take(generics.count()))
tcx.mk_args(&self[..generics.count()])
Copy link
Member Author

@fmease fmease Jun 12, 2025

Choose a reason for hiding this comment

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

This one wasn't tested in isolation (three perf runs are already a lot (I had to narrow down what is and what isn't perf relevant)) but I presume it to be helping since slicing & slice interning should generally be faster than iterating & "iterable interning" and this function is semi hot / lukewarm I'm pretty sure.

The first approach (which contains this change) yielded more improvements (results: #142289 (comment) (e.g., for image)) than the 1st commit (the assert changes) (results: #142289 (comment)), so this one might be the cause?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could rerun perf for this change / commit only (which seems a bit overkill) or just drop it entirely? WDYT?

@fmease
Copy link
Member Author

fmease commented Jun 12, 2025

r? compiler-errors (since you've reacted in this thread) or lcnr or compiler

@fmease fmease marked this pull request as ready for review June 12, 2025 23:50
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 12, 2025
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

cool. i dont think we'll gain much insight by doing individual perf tests of all the tweaks here; the fact that we gain a bit of perf back anyways is good and the changes at least make the code more readable.

@compiler-errors
Copy link
Member

r=me when ci is green or sooner i dont care much

@fmease fmease changed the title [perf] trait_ref_own_args: Change assert to debug assert and use more slice interning over iterable interning [perf] trait_ref_own_args: Change asserts to debug asserts and use more slice interning over iterable interning Jun 12, 2025
@fmease fmease changed the title [perf] trait_ref_own_args: Change asserts to debug asserts and use more slice interning over iterable interning [perf] GenericArgs-related: Change asserts to debug asserts & use more slice interning over iterable interning Jun 13, 2025
@fmease
Copy link
Member Author

fmease commented Jun 13, 2025

@bors r=compiler-errors

@bors
Copy link
Collaborator

bors commented Jun 13, 2025

📌 Commit 3a31f62 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 Jun 13, 2025
@jieyouxu
Copy link
Member

@bors p=5 (to get some rollup=nevers through before new rollups)

@bors
Copy link
Collaborator

bors commented Jun 14, 2025

⌛ Testing commit 3a31f62 with merge 49a8ba0...

@bors
Copy link
Collaborator

bors commented Jun 14, 2025

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 14, 2025
@bors bors merged commit 49a8ba0 into rust-lang:master Jun 14, 2025
11 checks passed
@rustbot rustbot added this to the 1.89.0 milestone Jun 14, 2025
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing cc87afd (parent) -> 49a8ba0 (this PR)

Test differences

No test diffs found

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 49a8ba06848fa8f282fe9055b4178350970bb0ce --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. mingw-check-1: 1563.8s -> 2005.6s (28.3%)
  2. x86_64-apple-2: 4102.8s -> 5128.8s (25.0%)
  3. x86_64-apple-1: 5863.1s -> 7297.8s (24.5%)
  4. dist-apple-various: 7288.8s -> 6075.0s (-16.7%)
  5. x86_64-rust-for-linux: 2600.0s -> 2982.7s (14.7%)
  6. i686-gnu-2: 5301.8s -> 5941.4s (12.1%)
  7. i686-gnu-nopt-1: 7165.3s -> 7874.7s (9.9%)
  8. aarch64-gnu-debug: 3570.1s -> 3905.2s (9.4%)
  9. aarch64-apple: 4287.1s -> 4684.6s (9.3%)
  10. x86_64-gnu-aux: 5839.9s -> 6368.6s (9.1%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@fmease fmease deleted the maybe-perf-gen-args branch June 14, 2025 22:52
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (49a8ba0): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-0.3%, -0.1%] 15
Improvements ✅
(secondary)
-1.2% [-4.7%, -0.1%] 13
All ❌✅ (primary) -0.2% [-0.3%, -0.1%] 15

Max RSS (memory usage)

Results (secondary -2.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) - - 0

Cycles

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

Binary size

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

Bootstrap: 756.218s -> 758.463s (0.30%)
Artifact size: 372.24 MiB -> 372.25 MiB (0.00%)

RalfJung pushed a commit to RalfJung/miri that referenced this pull request Jun 15, 2025
[perf] `GenericArgs`-related: Change asserts to debug asserts & use more slice interning over iterable interning

1. The 1st commit yields the following perf gains: [#142289 (comment)](rust-lang/rust#142289 (comment)).
2. The 2nd commit might also have a minor positive perf impact, however that one wasn't tested in isolation.

For reference, the initial approach rust-lang/rust@c7e6acc (results: rust-lang/rust#142289 (comment)) had a lot more changes (apart from what's now contained in commit 1 and 2) which seemed to be perf irrelevant (cf. the partial countercheck in rust-lang/rust@6f82bf1 (results: rust-lang/rust#142289 (comment)).
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jun 16, 2025
[perf] `GenericArgs`-related: Change asserts to debug asserts & use more slice interning over iterable interning

1. The 1st commit yields the following perf gains: [#142289 (comment)](rust-lang/rust#142289 (comment)).
2. The 2nd commit might also have a minor positive perf impact, however that one wasn't tested in isolation.

For reference, the initial approach rust-lang/rust@c7e6acc (results: rust-lang/rust#142289 (comment)) had a lot more changes (apart from what's now contained in commit 1 and 2) which seemed to be perf irrelevant (cf. the partial countercheck in rust-lang/rust@6f82bf1 (results: rust-lang/rust#142289 (comment)).
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.

6 participants