Skip to content

Conversation

@bvanjoi
Copy link
Contributor

@bvanjoi bvanjoi commented Sep 2, 2025

Fixes #145741

Performance test results from local for #145741:

time cargo clean && cargo build: 20.60s
time cargo +stage1 clean && cargo +stage1 build: 11.29s

I'm uncertain if this is a completely correct fix, as I've just reviewed the privacy update logic and it appears that a single update should suffice in the alias term. Feel free to close this if there are any algorithmic inaccuracies, and I'll investigate further.

@rustbot
Copy link
Collaborator

rustbot commented Sep 2, 2025

r? @SparrowLii

rustbot has assigned @SparrowLii.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Sep 2, 2025
@lqd
Copy link
Member

lqd commented Sep 2, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 2, 2025
privacy: cache for trait ref in projection
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 2, 2025
@rust-bors
Copy link

rust-bors bot commented Sep 2, 2025

☀️ Try build successful (CI)
Build commit: 97bca8b (97bca8b377025fbbb752947ef69ee3c8bc9ec6f5, parent: a2c8b0b92c14b02f0b3f96a0d5296f1090dc286b)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (97bca8b): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

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.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@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.1% [0.1%, 0.2%] 12
Regressions ❌
(secondary)
0.1% [0.1%, 0.2%] 5
Improvements ✅
(primary)
-0.3% [-0.4%, -0.1%] 7
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.0% [-0.4%, 0.2%] 19

Max RSS (memory usage)

Results (primary -0.1%)

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

mean range count
Regressions ❌
(primary)
1.3% [1.3%, 1.3%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.6% [-1.6%, -1.6%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.1% [-1.6%, 1.3%] 2

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: 465.026s -> 467.402s (0.51%)
Artifact size: 388.33 MiB -> 388.34 MiB (0.00%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Sep 2, 2025
@SparrowLii
Copy link
Member

r? @petrochenkov Could you have a look of this, Vadim?

@rustbot rustbot assigned petrochenkov and unassigned SparrowLii Sep 30, 2025
let (trait_ref, assoc_args) = projection.trait_ref_and_own_args(tcx);
try_visit!(self.visit_trait(trait_ref));
if self.visited_trait_ref_in_projection.insert(trait_ref) {
try_visit!(self.visit_trait(trait_ref));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is only correct to do if in all concrete DefIdVisitors visit_trait always does the same thing for the same trait_ref and that thing is not affected by mutable state in the visitor.

Copy link
Contributor

Choose a reason for hiding this comment

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

TypePrivacyVisitor and SearchInterfaceForPrivateItemsVisitor clearly satisfy that condition by not having any mutable state, but I'm not so sure about ReachEverythingInTheInterfaceVisitor and ReachableContext.

Copy link
Contributor

@petrochenkov petrochenkov Oct 8, 2025

Choose a reason for hiding this comment

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

ReachEverythingInTheInterfaceVisitor and ReachableContext seem to also be idempotent.

@petrochenkov
Copy link
Contributor

I want to check some different caching strategies for this in #147486.
@rustbot blocked

From local testing, caching at DefId level doesn't help with #145741, you have to skip larger pieces of code to improve compilation times for it.

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 8, 2025
@petrochenkov
Copy link
Contributor

Caching in this PR is overfit to one specific test case, #147486 (comment) shows that you can achieve the same effect in a more general way by caching all ty::Aliases.
(In my local testing ty::Alias caching still sped up the example from #145741 more than 2x.)

You could apply the changes from #147486 to this PR, or I can just land #147486 instead.
@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-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Oct 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 21, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

<<Mask as TypeTupleAccess>::_5 as MaskBit>::Pick<Pick<5>>,
>;

fn main() {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it makes sense to add this to UI tests, UI tests do not tests whether something compiles fast or slow, so it will mostly just slow down the testing.
It could potentially be added as a stress benchmark to https://github.com/rust-lang/rustc-perf though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could potentially be added as a stress benchmark to https://github.com/rust-lang/rustc-perf though.

This example seems like a good fit for the secondary benchmark suite. 🤔

Copy link
Member

Choose a reason for hiding this comment

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

The benchmark is currently too slow for rustc-perf, it takes ~25s just to check, and we run a lot of configs three times, so this would take many minutes to benchmark.

In case you didn't build this manually, but used some code generator, could you generate a faster version? E.g. with less items in the TypeTuple.

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Oct 22, 2025

or I can just land #147486 instead.

I think that works since #147386 is already good enough, so I'll close this one.

@bvanjoi bvanjoi closed this Oct 22, 2025
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 22, 2025
bors added a commit that referenced this pull request Oct 23, 2025
privacy: Introduce some caching to type visiting in `DefIdVisitorSkeleton`

The caching fixes compilation speed issues in special cases like #145741, without introducing too much overhead in general cases.

I tried to cache more, but it caused regressions from the caching overhead, like it can be seen from benchmark runs below.

Inspired by #146128.
Closes #145741.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Oct 24, 2025
privacy: Introduce some caching to type visiting in `DefIdVisitorSkeleton`

The caching fixes compilation speed issues in special cases like rust-lang/rust#145741, without introducing too much overhead in general cases.

I tried to cache more, but it caused regressions from the caching overhead, like it can be seen from benchmark runs below.

Inspired by rust-lang/rust#146128.
Closes rust-lang/rust#145741.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. 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.

Exponential slow down in compilation speed (because of visiblity checking?)

7 participants