Skip to content

Avoid the would-change check for bitset chunks that are unique#153754

Closed
Zalathar wants to merge 2 commits intorust-lang:mainfrom
Zalathar:would-change
Closed

Avoid the would-change check for bitset chunks that are unique#153754
Zalathar wants to merge 2 commits intorust-lang:mainfrom
Zalathar:would-change

Conversation

@Zalathar
Copy link
Copy Markdown
Member


ChunkedBitSet goes out of its way to check in advance whether a union/subtract/intersect operation would actually modify any bits, to avoid calling Rc::make_mut if possible.

But in the case where the Rc is already unique (i.e. Rc::get_mut succeeds), it's cheaper to skip the would-change check entirely, and just modify the words eagerly.


This PR also adds some more thorough tests for ChunkedBitSet's union/subtract/intersect methods, which would have pinpointed a serious bug in the previous PR.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 12, 2026
@Zalathar
Copy link
Copy Markdown
Member Author

Let's try benchmarking a version of this change that doesn't accidentally skip all the important work:

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Mar 12, 2026
Avoid the would-change check for bitset chunks that are unique
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 12, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Mar 12, 2026

☀️ Try build successful (CI)
Build commit: 047dc4e (047dc4e3e9b4059fc6e425c531cad1c42ca17e54, parent: d1ee5e59a964a419b84b760812a35075034f4861)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (047dc4e): 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)
2.1% [1.1%, 3.3%] 4
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-0.2%, -0.1%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.4% [-0.2%, 3.3%] 6

Max RSS (memory usage)

Results (secondary 1.8%)

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)
1.8% [1.8%, 1.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
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: 480.488s -> 479.262s (-0.26%)
Artifact size: 394.87 MiB -> 394.89 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 Mar 12, 2026
@Zalathar
Copy link
Copy Markdown
Member Author

Oh, that's disappointing. Perhaps the vectorized equality test is actually faster than an unconditional update, on average.

@Zalathar Zalathar closed this Mar 12, 2026
@Zalathar Zalathar deleted the would-change branch March 12, 2026 06:27
@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 Mar 12, 2026
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.

3 participants