Skip to content

Cache block seeking results for initialized_at_terminator and _exit - #162450

Open
jackh726 wants to merge 1 commit into
rust-lang:mainfrom
jackh726:polonius-cleanups-4
Open

Cache block seeking results for initialized_at_terminator and _exit#162450
jackh726 wants to merge 1 commit into
rust-lang:mainfrom
jackh726:polonius-cleanups-4

Conversation

@jackh726

@jackh726 jackh726 commented Sep 8, 2026

Copy link
Copy Markdown
Member

Caching the block values post-seek results in significant performance wins (especially on pathological benchmarks). These wins extend to NLL, too.

Possibly, this caching could be done further up the stack (more generically), but figured this is a "safer" approach - rather than dealing with other potential fallout.

r? lqd

LLM-generated perf summary table image

@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 8, 2026
@jackh726

jackh726 commented Sep 8, 2026

Copy link
Copy Markdown
Member Author

Disclosure: An LLM was used to identify this perf effect and to check the performance of the solution.

@jackh726

jackh726 commented Sep 8, 2026

Copy link
Copy Markdown
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 Sep 8, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 8, 2026
Cache block seeking results for initialized_at_terminator and _exit
Comment on lines +308 to +312
if self.cx.initialized_at_terminator(location.block, mpi) {
let inserted = self.drop_live_at.insert(drop_point);
// Right now, we should visit a drop_point twice.
// If we do, this trigger a debug assert so we need we can optimize.
debug_assert!(inserted, "drop point should not have been visited yet");

@jackh726 jackh726 Sep 8, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is technically completely unrelated - but sticking it in as a drive-by pass. I had a though that we might be visiting drop points twice (and thus could switch these conditions for a perf benefit) - but the iteration here is unique.

View changes since the review

Comment on lines +531 to +532
// Ensure self.flow_inits is initialized
let _ = self.flow_inits();

@jackh726 jackh726 Sep 8, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought about changing fn flow_inits to be something like fn ensure_flow_inits(&mut _). Then this could get moved into initialized_at too.

View changes since the review

block,
mpi,
|flow_inits: &mut ResultsCursor<'_, 'tcx, MaybeInitializedPlaces<'_, 'tcx>>| {
let terminator_location = self.typeck.body.terminator_loc(block);

@jackh726 jackh726 Sep 8, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Another alternative: pass self.typeck into initialized_at and call this there.

View changes since the review

flow_inits: &mut ResultsCursor<'_, 'tcx, MaybeInitializedPlaces<'_, 'tcx>>,
block: BasicBlock,
mpi: MovePathIndex,
seek: impl FnOnce(&mut ResultsCursor<'_, 'tcx, MaybeInitializedPlaces<'_, 'tcx>>),

@jackh726 jackh726 Sep 8, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Another option that may work: a fn(&mut ResultsCursor<'_, 'tcx, MaybeInitializedPlaces<'_, 'tcx>>, Location). Then I think you could just pass e.g. ResultsCursor::seek_before_primary_effect instead of a closure. Not sure if lifetimes allow though.

View changes since the review

@rust-bors

rust-bors Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 2bf7717 (2bf77177e903bc66ebe183042d1ad525545e866a)
Base parent: 2e6e39f (2e6e39f684e1c6b0bbfe16593a23d901e61219ca)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (2bf7717): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@bors rollup=never rustc-perf
@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
Improvements ✅
(primary)
-3.1% [-5.7%, -0.2%] 9
Improvements ✅
(secondary)
-4.1% [-5.7%, -0.2%] 10
All ❌✅ (primary) -3.1% [-5.7%, -0.2%] 9

Max RSS (memory usage)

Results (primary -0.4%)

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

mean range count
Regressions ❌
(primary)
0.5% [0.5%, 0.5%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-1.4%, -0.4%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.4% [-1.4%, 0.5%] 4

Cycles

Results (primary -1.4%, secondary -0.3%)

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

mean range count
Regressions ❌
(primary)
0.4% [0.4%, 0.4%] 1
Regressions ❌
(secondary)
3.7% [3.7%, 3.7%] 1
Improvements ✅
(primary)
-1.8% [-2.6%, -0.7%] 4
Improvements ✅
(secondary)
-2.2% [-2.4%, -2.1%] 2
All ❌✅ (primary) -1.4% [-2.6%, 0.4%] 5

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 482.327s -> 479.101s (-0.67%)
Artifact size: 403.54 MiB -> 403.54 MiB (0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants