Skip to content

Don't rerun goals if none of their vars have changed #141500

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
May 26, 2025

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented May 24, 2025

r? @ghost

Alternative to #141488. I'm pretty sure that we don't need to re-run the goal at all if the inputs don't change... 🤔

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 24, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 24, 2025

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@lqd
Copy link
Member

lqd commented May 24, 2025

perf perf PERF (to the tune of teeth teeth TEETH) @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 May 24, 2025
bors added a commit that referenced this pull request May 24, 2025
[PERF] Don't rerun goals if none of their vars have changed

r? `@ghost`

Alternative to #141488. I'm pretty sure that we don't need to re-run the goal at all if the inputs don't change... 🤔
@bors
Copy link
Collaborator

bors commented May 24, 2025

⌛ Trying commit 2d718c1 with merge 4c02404...

@bors
Copy link
Collaborator

bors commented May 24, 2025

☀️ Try build successful - checks-actions
Build commit: 4c02404 (4c02404f6a3e21d721602e21942b9ee0e3175b14)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (4c02404): comparison URL.

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

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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.6% [0.3%, 0.9%] 6
Improvements ✅
(primary)
-0.2% [-0.3%, -0.1%] 13
Improvements ✅
(secondary)
-1.8% [-17.6%, -0.2%] 23
All ❌✅ (primary) -0.2% [-0.3%, -0.1%] 13

Max RSS (memory usage)

Results (primary 0.8%, secondary 5.5%)

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.9% [1.8%, 2.0%] 2
Regressions ❌
(secondary)
6.7% [3.2%, 9.6%] 7
Improvements ✅
(primary)
-1.2% [-1.2%, -1.2%] 1
Improvements ✅
(secondary)
-2.8% [-2.8%, -2.8%] 1
All ❌✅ (primary) 0.8% [-1.2%, 2.0%] 3

Cycles

Results (secondary -5.4%)

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.9% [0.9%, 0.9%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-8.6% [-11.7%, -5.6%] 2
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 777.23s -> 776.477s (-0.10%)
Artifact size: 366.32 MiB -> 366.38 MiB (0.02%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels May 24, 2025
@compiler-errors
Copy link
Member 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 May 25, 2025
@bors
Copy link
Collaborator

bors commented May 25, 2025

⌛ Trying commit ca34794 with merge 7e9d4c6...

bors added a commit that referenced this pull request May 25, 2025
[PERF] Don't rerun goals if none of their vars have changed

r? `@ghost`

Alternative to #141488. I'm pretty sure that we don't need to re-run the goal at all if the inputs don't change... 🤔
@bors
Copy link
Collaborator

bors commented May 25, 2025

☀️ Try build successful - checks-actions
Build commit: 7e9d4c6 (7e9d4c67ad1d4d4bcd517d72759241344f1854e5)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7e9d4c6): comparison URL.

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

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 the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.2%, 0.4%] 5
Improvements ✅
(primary)
-0.1% [-0.2%, -0.1%] 5
Improvements ✅
(secondary)
-6.1% [-18.1%, -2.2%] 6
All ❌✅ (primary) -0.1% [-0.2%, -0.1%] 5

Max RSS (memory usage)

Results (primary 0.8%, secondary -3.3%)

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.8% [1.6%, 2.0%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.3% [-1.3%, -1.3%] 1
Improvements ✅
(secondary)
-3.3% [-4.2%, -2.0%] 14
All ❌✅ (primary) 0.8% [-1.3%, 2.0%] 3

Cycles

Results (secondary -0.1%)

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)
3.5% [1.2%, 4.7%] 5
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-9.2% [-12.3%, -6.1%] 2
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 775.592s -> 776.167s (0.07%)
Artifact size: 366.33 MiB -> 366.31 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 25, 2025
@@ -24,6 +24,12 @@ pub struct OpaqueTypeStorageEntries {
duplicate_entries: usize,
}

impl rustc_type_ir::inherent::OpaqueTypeStorageEntries for OpaqueTypeStorageEntries {
fn needs_reevaluation(self, canonicalized: usize) -> bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

ew but also i dont think we need a better API For now.

@@ -53,10 +53,10 @@ where
{
/// Canonicalizes the goal remembering the original values
/// for each bound variable.
pub(super) fn canonicalize_goal<T: TypeFoldable<I>>(
pub(super) fn canonicalize_goal(
Copy link
Member Author

Choose a reason for hiding this comment

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

didnt need to be this generic :>

(
Certainty::Yes,
NestedNormalizationGoals(
goals.into_iter().map(|(s, g, _)| (s, g)).collect(),
Copy link
Member Author

Choose a reason for hiding this comment

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

we could actually canonicalize these keys i think, which may prevent a rerun in the parent query

@@ -660,6 +733,8 @@ where
// looking at the "has changed" return from evaluate_goal,
// because we expect the `unconstrained_rhs` part of the predicate
// to have changed -- that means we actually normalized successfully!
// FIXME: Do we need to eagerly resolve here? Or should we check
// if the cache key has any changed vars?
let with_resolved_vars = self.resolve_vars_if_possible(goal);
Copy link
Member Author

Choose a reason for hiding this comment

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

this resolve call feels strange -- we should probably be checking if any of the vars changed at all?

@compiler-errors compiler-errors changed the title [PERF] Don't rerun goals if none of their vars have changed Don't rerun goals if none of their vars have changed May 25, 2025
@compiler-errors
Copy link
Member Author

Minor improvement in syn. Some of the non new-solver scenarios are back to neutral; not sure what to make of those, but whatever. I think this is fine to be reviewed now.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

👍

naming-wise I am not totally happy yet 🤔 CanonicalGoalCacheKey seems somewhat... misleading/unhelpful

  • GoalStalledOn maybe? also, add a comment to that struct :3

) -> (
Result<(HasChanged, Certainty), NoSolution>,
Result<(HasChanged, Certainty, CanonicalGoalCacheKey<Self::Interner>), NoSolution>,
Copy link
Contributor

Choose a reason for hiding this comment

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

can you move (HasChanged, Certainty, CanonicalGoalCacheKey<Self::Interner>) into a struct.

Copy link
Member Author

Choose a reason for hiding this comment

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

Unlike the one below, this one actually does clean up a lot 👍

@@ -115,7 +116,7 @@ where

pub(super) search_graph: &'a mut SearchGraph<D>,

nested_goals: Vec<(GoalSource, Goal<I, I::Predicate>)>,
nested_goals: Vec<(GoalSource, Goal<I, I::Predicate>, Option<CanonicalGoalCacheKey<I>>)>,
Copy link
Contributor

Choose a reason for hiding this comment

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

same with this tuple

Copy link
Member Author

Choose a reason for hiding this comment

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

For a single use? I don't really feel like that's really beneficial. Notably, this isn't the same tuple of (Goal, Option<CacheKey>) that's stored in the fulfillment context.

@compiler-errors
Copy link
Member Author

I introduced a new GoalEvaluation<'tcx> struct that holds the response + stalled vars from the evaluate_goal_* functions, and renamed the "cache key" struct (whose name stopped being descriptive when I changed the approach) to GoalStalledOn<'tcx>.

Threw another random commit into the PR (5893b58) b/c I didn't want to open a totally separate PR for just a one liner.

@lcnr lcnr self-assigned this May 26, 2025
… new solver is more complete

Just a totally unrelated nitpick I'm folding into the PR, since it's
code I'd like for us to prune when the new solver lands.
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented May 26, 2025

📌 Commit f0bcb0e has been approved by lcnr

It is now in the queue for this repository.

@compiler-errors
Copy link
Member Author

@bors rollup=never

@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 26, 2025
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented May 26, 2025

📌 Commit e2215a8 has been approved by lcnr

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented May 26, 2025

🌲 The tree is currently closed for pull requests below priority 10. This pull request will be tested once the tree is reopened.

bors added a commit that referenced this pull request May 26, 2025
add additional `TypeFlags` fast paths

Some crates, e.g. `diesel`, have items with a lot of where-clauses (more than 150). In these cases checking the `TypeFlags` of the whole `param_env` can be very beneficial.

This adds `fn fold_clauses` to mirror the existing `fn visit_clauses` and then uses this in folders which fold `ParamEnv`s.

Split out from #141451, depends on #141500.

r? `@compiler-errors`
@bors
Copy link
Collaborator

bors commented May 26, 2025

⌛ Testing commit e2215a8 with merge 40d2563...

@bors
Copy link
Collaborator

bors commented May 26, 2025

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing 40d2563 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label May 26, 2025
@bors bors merged commit 40d2563 into rust-lang:master May 26, 2025
8 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 26, 2025
Copy link

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 9c0bcb5 (parent) -> 40d2563 (this PR)

Test differences

Show 2 test diffs

2 doctest diffs were found. These are ignored, as they are noisy.

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard 40d2563ea200f9327a8cb8b99a0fb82f75a7365c --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. dist-x86_64-apple: 11397.7s -> 8025.7s (-29.6%)
  2. aarch64-gnu-debug: 4901.5s -> 4063.4s (-17.1%)
  3. aarch64-gnu: 6806.1s -> 7655.1s (12.5%)
  4. x86_64-apple-2: 5442.5s -> 4830.9s (-11.2%)
  5. aarch64-apple: 4627.1s -> 4125.6s (-10.8%)
  6. x86_64-msvc-ext1: 7401.4s -> 6954.9s (-6.0%)
  7. dist-x86_64-msvc-alt: 7797.8s -> 7331.5s (-6.0%)
  8. x86_64-msvc-1: 8126.4s -> 8587.5s (5.7%)
  9. dist-x86_64-musl: 7411.5s -> 7756.6s (4.7%)
  10. dist-aarch64-apple: 6152.9s -> 5875.9s (-4.5%)
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.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (40d2563): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
-0.1% [-0.2%, -0.1%] 2
Improvements ✅
(secondary)
-4.1% [-17.9%, -0.3%] 9
All ❌✅ (primary) -0.1% [-0.2%, -0.1%] 2

Max RSS (memory usage)

Results (primary -0.7%)

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.0% [1.0%, 1.0%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.5% [-1.6%, -1.4%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-1.6%, 1.0%] 3

Cycles

Results (secondary -9.1%)

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)
-9.1% [-12.3%, -6.0%] 2
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 777.056s -> 778.13s (0.14%)
Artifact size: 366.33 MiB -> 366.42 MiB (0.02%)

@rustbot rustbot removed the perf-regression Performance regression. label May 26, 2025
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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants