Skip to content

interpret: copy_provenance: avoid large intermediate buffer for large repeat counts#146331

Merged
bors merged 2 commits into
rust-lang:masterfrom
RalfJung:copy-prov-repeat
Sep 17, 2025
Merged

interpret: copy_provenance: avoid large intermediate buffer for large repeat counts#146331
bors merged 2 commits into
rust-lang:masterfrom
RalfJung:copy-prov-repeat

Conversation

@RalfJung

@RalfJung RalfJung commented Sep 8, 2025

Copy link
Copy Markdown
Member

Copying provenance worked in this odd way where the "preparation" phase (which is supposed to just extract the necessary information from the source range) already did all the work of repeating the result N times for the target range. This was needed to use the existing insert_presorted function on SortedMap.

This PR generalizes insert_presorted so that we can avoid this odd structure on copy-provenance, and maybe even improve performance.

@rustbot

rustbot commented Sep 8, 2025

Copy link
Copy Markdown
Collaborator

r? @petrochenkov

rustbot has assigned @petrochenkov.
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 8, 2025
@rustbot

rustbot commented Sep 8, 2025

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@RalfJung

RalfJung commented Sep 8, 2025

Copy link
Copy Markdown
Member Author

@bors try
@rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors Bot added a commit that referenced this pull request Sep 8, 2025
interpret: copy_provenance: avoid large intermediate buffer for large repeat counts
@rust-bors

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, 2025
self.ptrs.insert_presorted(
copy.ptrs.iter().map(|&(offset, reloc)| (shift_offset(i, offset), reloc)),
);
}

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 the one change that may cost us performance... if there's a bunch of provenance after the range we are copying into, but none in the given range (i.e. we are hitting the fast-path in insert_presorted), it'll be moved around each time.

We'd need a single iterator yielding the entire repeated range to avoid this... which I guess is possible. Maybe I should try that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's pretty common for such operations to only be used when the rest is uninit. I guess that will still pessimize the other cases, but without more benchmarks I don't know if we should try anything.

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.

FWIW the 2nd commit does implement the "single iterator" strategy to avoid copying N times for an array of size N.

insert_presorted could still have its slowpath improved by a lot, but that's orthogonal to this PR.

@rust-bors

rust-bors Bot commented Sep 8, 2025

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 6215de8 (6215de8cada28c90f56dbebb1464cf1094884ed5, parent: beeb8e3af54295ba494c250e84ecda4c2c5d85ff)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (6215de8): comparison URL.

Overall result: ❌ regressions - 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.2% [0.2%, 0.2%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 4.1%, secondary 1.3%)

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

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

Cycles

Results (primary 0.1%, secondary 2.9%)

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

mean range count
Regressions ❌
(primary)
2.2% [2.2%, 2.2%] 1
Regressions ❌
(secondary)
2.9% [2.7%, 3.1%] 2
Improvements ✅
(primary)
-2.1% [-2.1%, -2.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.1% [-2.1%, 2.2%] 2

Binary size

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

Bootstrap: 466.876s -> 466.292s (-0.13%)
Artifact size: 387.41 MiB -> 387.38 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 8, 2025
@bors

bors commented Sep 9, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #146360) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot

rustbot commented Sep 9, 2025

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@RalfJung

RalfJung commented Sep 9, 2025

Copy link
Copy Markdown
Member Author

@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 9, 2025
interpret: copy_provenance: avoid large intermediate buffer for large repeat counts
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 9, 2025
@rust-bors

rust-bors Bot commented Sep 9, 2025

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: cd436dc (cd436dc33f3489ca3d38a80e30b843868de52c6e, parent: be8de5d6a0fc5cb2924e174a809a0aff303f281a)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (cd436dc): comparison URL.

Overall result: ❌✅ regressions and 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.2% [0.2%, 0.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

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

Cycles

Results (primary -2.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)
- - 0
Improvements ✅
(primary)
-2.1% [-2.1%, -2.1%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.1% [-2.1%, -2.1%] 1

Binary size

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

Bootstrap: 467.841s -> 468.775s (0.20%)
Artifact size: 387.52 MiB -> 387.56 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 9, 2025
@RalfJung

Copy link
Copy Markdown
Member Author

This looks slightly better than the first run (which only had the first commit), though that might be noise.

@petrochenkov

Copy link
Copy Markdown
Contributor

r? compiler
I'm on vacation and this is not my area.

@rustbot rustbot assigned davidtwco and unassigned petrochenkov Sep 14, 2025
@RalfJung

Copy link
Copy Markdown
Member Author

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned davidtwco Sep 14, 2025
@rustbot

rustbot commented Sep 14, 2025

Copy link
Copy Markdown
Collaborator

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@oli-obk oli-obk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the things we do for perf 😆

View changes since this review

pub fn insert_presorted(
&mut self,
// We require `TrustedLen` to ensure that the `splice` below is actually efficient.
mut elements: impl Iterator<Item = (K, V)> + DoubleEndedIterator + TrustedLen,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could use IntoIterator<Item = (K, V), Iter: DoubleEndedIterator + TrustedLen> to avoid needing to change callers, but since it's mostly tests, doesn't really matter

@oli-obk

oli-obk commented Sep 16, 2025

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Sep 16, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 7abbc9c has been approved by oli-obk

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 Sep 16, 2025
@bors

bors commented Sep 17, 2025

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 7abbc9c with merge 5d1b897...

@bors

bors commented Sep 17, 2025

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 5d1b897 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 17, 2025
@bors bors merged commit 5d1b897 into rust-lang:master Sep 17, 2025
11 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Sep 17, 2025
@github-actions

Copy link
Copy Markdown
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 ce6daf3 (parent) -> 5d1b897 (this PR)

Test differences

Show 3 test diffs

3 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 5d1b897a07dc30d810dd541795125c1c216266c7 --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-apple-various: 3369.0s -> 4051.3s (20.3%)
  2. i686-gnu-2: 5400.6s -> 6448.9s (19.4%)
  3. dist-x86_64-apple: 7189.6s -> 8481.1s (18.0%)
  4. x86_64-gnu-llvm-20-1: 3228.5s -> 3779.3s (17.1%)
  5. pr-check-1: 1358.2s -> 1558.7s (14.8%)
  6. aarch64-apple: 6624.5s -> 5656.9s (-14.6%)
  7. x86_64-gnu-llvm-20: 2476.2s -> 2830.4s (14.3%)
  8. i686-gnu-1: 7465.5s -> 8518.7s (14.1%)
  9. pr-check-2: 2199.3s -> 2500.5s (13.7%)
  10. x86_64-rust-for-linux: 2645.6s -> 2992.0s (13.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.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (5d1b897): comparison URL.

Overall result: ❌✅ regressions and 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.2% [0.2%, 0.4%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -9.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)
-9.2% [-9.2%, -9.2%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -9.2% [-9.2%, -9.2%] 1

Cycles

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

Binary size

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

Bootstrap: 472.939s -> 471.616s (-0.28%)
Artifact size: 387.93 MiB -> 387.94 MiB (0.00%)

@RalfJung RalfJung deleted the copy-prov-repeat branch September 19, 2025 14:47
makai410 pushed a commit to makai410/rust that referenced this pull request Nov 8, 2025
interpret: copy_provenance: avoid large intermediate buffer for large repeat counts

Copying provenance worked in this odd way where the "preparation" phase (which is supposed to just extract the necessary information from the source range) already did all the work of repeating the result N times for the target range. This was needed to use the existing `insert_presorted` function on `SortedMap`.

This PR generalizes `insert_presorted` so that we can avoid this odd structure on copy-provenance, and maybe even improve performance.
makai410 pushed a commit to makai410/rust that referenced this pull request Nov 10, 2025
interpret: copy_provenance: avoid large intermediate buffer for large repeat counts

Copying provenance worked in this odd way where the "preparation" phase (which is supposed to just extract the necessary information from the source range) already did all the work of repeating the result N times for the target range. This was needed to use the existing `insert_presorted` function on `SortedMap`.

This PR generalizes `insert_presorted` so that we can avoid this odd structure on copy-provenance, and maybe even improve performance.
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.

7 participants