Skip to content
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

Introduce MixedBitSet #133891

Merged
merged 6 commits into from
Dec 9, 2024
Merged

Introduce MixedBitSet #133891

merged 6 commits into from
Dec 9, 2024

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented Dec 5, 2024

ChunkedBitSet is good at avoiding excessive memory usage for programs with very large functgions where dataflow bitsets have very large domain sizes. But it's overly heavyweight for small bitsets, because any non-empty ChunkedBitSet takes up at least 256 bytes.

This PR introduces MixedBitSet, which is a simple bitset that uses BitSet for small/medium bitsets and ChunkedBitSet for large bitsets. It's a speed and memory usage win.

r? @Mark-Simulacrum

These blocks are currently interleaved with `ChunkedBitSet` blocks. It
makes things hard to find and has annoyed me for a while.
@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 Dec 5, 2024
@nnethercote nnethercote changed the title Mixed bit set Introduce MixedBitSet Dec 5, 2024
@nnethercote
Copy link
Contributor 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 Dec 5, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 5, 2024
@bors
Copy link
Contributor

bors commented Dec 5, 2024

⌛ Trying commit 853e69c with merge c103766...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Dec 5, 2024

☀️ Try build successful - checks-actions
Build commit: c103766 (c103766e3311d9facbec90ad63ac7cfb7dfc4ce8)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (c103766): 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.7% [0.2%, 1.1%] 6
Improvements ✅
(primary)
-0.6% [-1.3%, -0.1%] 70
Improvements ✅
(secondary)
-0.7% [-2.3%, -0.1%] 29
All ❌✅ (primary) -0.6% [-1.3%, -0.1%] 70

Max RSS (memory usage)

Results (primary -1.6%, secondary -5.2%)

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)
-1.6% [-1.9%, -1.4%] 2
Improvements ✅
(secondary)
-5.2% [-5.4%, -5.1%] 2
All ❌✅ (primary) -1.6% [-1.9%, -1.4%] 2

Cycles

Results (primary -1.0%, secondary -2.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
Improvements ✅
(primary)
-1.0% [-1.3%, -0.4%] 13
Improvements ✅
(secondary)
-2.4% [-2.9%, -2.0%] 6
All ❌✅ (primary) -1.0% [-1.3%, -0.4%] 13

Binary size

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

Bootstrap: 769.678s -> 766.319s (-0.44%)
Artifact size: 330.86 MiB -> 330.88 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 5, 2024
It just uses `BitSet` for small/medium sizes (<= 2048 bits) and
`ChunkedBitSet` for larger sizes. This is good because `ChunkedBitSet`
is slow and memory-hungry at smaller sizes.
It's a performance win because `MixedBitSet` is faster and uses less
memory than `ChunkedBitSet`.

Also reflow some overlong comment lines in
`lint_tail_expr_drop_order.rs`.
@nnethercote nnethercote marked this pull request as ready for review December 5, 2024 09:27
@rustbot
Copy link
Collaborator

rustbot commented Dec 5, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@nnethercote
Copy link
Contributor Author

After #133431 removed HybridBitSet it might seem strange to immediately introduce a new bitset. The rationale is:

  • it's a perf win; and
  • MixedBitSet is a lot simpler than HybridBitSet.

This was referenced Dec 5, 2024
Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

r=me with or without nits fixed

A `ChunkedBitSet` has to be at least 2048 bits for it to outperform a
`BitSet`, because that's the chunk size. The largest `SparseBitMatrix`
encountered when compiling the compiler and the entire rustc-perf
benchmark suite is less than 600 bits.

This change is a tiny perf win, but the motivation is more about
avoiding uses of `ChunkedBitSet` outside of `MixedBitSet`.

The test change is necessary to avoid hitting the `<BitSet<T> as
BitRelations<ChunkedBitSet<T>>>::subtract` method that has
`unimplemented!` in its body and isn't otherwise used.
Just minimizing uses of `ChunkedBitSet`.
`ChunkedBitSet` is no longer used directly by dataflow analyses, with
`MixedBitSet` replacing it in those contexts.
@nnethercote
Copy link
Contributor Author

I addressed the comments.

@bors r=Mark-Simulacrum

@bors
Copy link
Contributor

bors commented Dec 8, 2024

📌 Commit fa6ceba has been approved by Mark-Simulacrum

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 Dec 8, 2024
@bors
Copy link
Contributor

bors commented Dec 9, 2024

⌛ Testing commit fa6ceba with merge f6cb952...

@bors
Copy link
Contributor

bors commented Dec 9, 2024

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing f6cb952 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 9, 2024
@bors bors merged commit f6cb952 into rust-lang:master Dec 9, 2024
7 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Dec 9, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f6cb952): comparison URL.

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

Our benchmarks found a performance regression caused by this PR.
This might be an actual regression, but it can also be just noise.

Next Steps:

  • If the regression was expected or you think it can be justified,
    please write a comment with sufficient written justification, and add
    @rustbot label: +perf-regression-triaged to it, to mark the regression as triaged.
  • If you think that you know of a way to resolve the regression, try to create
    a new PR with a fix for the regression.
  • If you do not understand the regression or you think that it is just noise,
    you can ask the @rust-lang/wg-compiler-performance working group for help (members of this group
    were already notified of this PR).

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

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.2%, 1.0%] 8
Improvements ✅
(primary)
-0.6% [-1.3%, -0.2%] 67
Improvements ✅
(secondary)
-0.7% [-2.0%, -0.2%] 28
All ❌✅ (primary) -0.6% [-1.3%, -0.2%] 67

Max RSS (memory usage)

Results (primary 0.9%, secondary -1.0%)

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)
2.1% [1.2%, 3.1%] 2
Regressions ❌
(secondary)
1.3% [1.3%, 1.3%] 1
Improvements ✅
(primary)
-1.5% [-1.5%, -1.5%] 1
Improvements ✅
(secondary)
-1.6% [-2.3%, -1.4%] 4
All ❌✅ (primary) 0.9% [-1.5%, 3.1%] 3

Cycles

Results (primary -1.0%, secondary -2.9%)

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)
-1.0% [-1.0%, -1.0%] 1
Improvements ✅
(secondary)
-2.9% [-4.8%, -2.1%] 14
All ❌✅ (primary) -1.0% [-1.0%, -1.0%] 1

Binary size

Results (secondary 0.0%)

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

Bootstrap: 769.074s -> 767.969s (-0.14%)
Artifact size: 330.87 MiB -> 330.85 MiB (-0.01%)

@Mark-Simulacrum Mark-Simulacrum added the perf-regression-triaged The performance regression has been triaged. label Dec 9, 2024
@Mark-Simulacrum
Copy link
Member

Overall positive, all primary benchmarks show improvement (or no change).

@nnethercote nnethercote deleted the MixedBitSet branch December 10, 2024 00:26
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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.

6 participants