Skip to content

Use Box<[Word]> for word storage in DenseBitSet - #161957

Open
Zalathar wants to merge 7 commits into
rust-lang:mainfrom
Zalathar:growable
Open

Use Box<[Word]> for word storage in DenseBitSet#161957
Zalathar wants to merge 7 commits into
rust-lang:mainfrom
Zalathar:growable

Conversation

@Zalathar

Copy link
Copy Markdown
Member

Since DenseBitSet has a fixed domain size, it doesn't need the capacity field of Vec. This shrinks the inline-size of DenseBitSet from 32 bytes to 24 bytes.

The main reason this wasn't done earlier is that GrowableBitSet does require resizing, and was using DenseBitSet as its internal representation.

Thus, most of this PR is separating the two bitset implementations, so that DenseBitSet is free to use a more appropriate storage type.

@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 Aug 29, 2026
@Zalathar

Copy link
Copy Markdown
Member Author

cc @panstromek

@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 Aug 29, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 29, 2026
Use `Box<[Word]>` for word storage in `DenseBitSet`
@Zalathar

Copy link
Copy Markdown
Member Author

For future work, we could potentially shrink DenseBitSet down to 16 bytes by only storing (pointer, domain_size) and inferring allocation length from the domain size. But that would require unsafe shenanigans that the implementation isn't ready for.

@rust-bors

rust-bors Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: cfa61c7 (cfa61c735d872ca7c526a0a3a312336e026fc444)
Base parent: 17fd5b8 (17fd5b8a37b6667b6cc137f3cc35f09759768a3b)

@rust-timer

This comment has been minimized.

@panstromek

panstromek commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Nice, I was going to try this one too, it should help cases when we store DenseBitSets in Vecs, like SparseBitMatrix. For those, it would be even better to store domain_size out of the datatructure completely and maybe store the data inline. That's part of the motivation for why I'm experimenting with making the DenseBitSet generic over storage (one experiment for this pattern is #161584) to make it possible to make these decisions per usage (and why I think your raw PR would make that easier, too).

As I was looking at the usages of these (DenseBitSets in Vecs, SparseBitMatrix), I found that they are often not quite optimally used anyway, so it might be better to just eliminate them, so I did one in #161850 and I think we can eliminate other ones too. That might reduce the impact of this PR, but we still probably have a ton of BitSets in other places where it'll help.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (cfa61c7): 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)
-0.5% [-0.8%, -0.2%] 4
Improvements ✅
(secondary)
-0.2% [-0.4%, -0.0%] 10
All ❌✅ (primary) -0.5% [-0.8%, -0.2%] 4

Max RSS (memory usage)

Results (primary 2.6%, secondary 1.5%)

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

mean range count
Regressions ❌
(primary)
2.6% [2.6%, 2.6%] 1
Regressions ❌
(secondary)
2.7% [0.8%, 6.3%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) 2.6% [2.6%, 2.6%] 1

Cycles

Results (primary 2.3%, secondary 4.1%)

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

mean range count
Regressions ❌
(primary)
2.3% [2.3%, 2.3%] 1
Regressions ❌
(secondary)
9.7% [2.1%, 14.5%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.3% [-4.3%, -4.3%] 2
All ❌✅ (primary) 2.3% [2.3%, 2.3%] 1

Binary size

Results (secondary -0.0%)

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)
-0.0% [-0.0%, -0.0%] 1
All ❌✅ (primary) - - 0

Bootstrap: 474.378s -> 479.269s (1.03%)
Artifact size: 402.85 MiB -> 402.83 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 29, 2026
@Zalathar
Zalathar marked this pull request as ready for review August 29, 2026 06:44
@rustbot

rustbot commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 29, 2026
@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 Aug 29, 2026
@rustbot

rustbot commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

r? @chenyukang

rustbot has assigned @chenyukang.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 20 candidates

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.

5 participants