Shawyeok opened a new pull request, #26128:
URL: https://github.com/apache/pulsar/pull/26128
### Motivation
Several batch-ack paths allocate a `BitSet` or `BitSetRecyclable` instance
only to compute a
cardinality or perform an AND/intersect on raw `long[]` word arrays. These
allocations are
unnecessary — the results can be computed directly via `Long.bitCount` and
bitwise operators.
### Modifications
**New `AckSetUtil` utility class** (`pulsar-common`):
| Method | Description |
|--------|-------------|
| `cardinality(long[])` | Popcount of a word array — no `BitSet` alloc |
| `intersect(long[], long[])` | Element-wise AND; result length = `min(len1,
len2)` |
| `cardinalityOfIntersection(long[], long[])` | Popcount of AND without
allocating a result array |
**Refactored call sites** — replaced allocation-heavy patterns with
`AckSetUtil` in:
- `Consumer` (broker) — `BitSet.valueOf(x).cardinality()` and
`BitSetRecyclable.create().resetWords(x).cardinality()` patterns (4 sites)
- `EntryBatchIndexesAcks` (broker) — same pattern (1 site)
- `PositionAckSetUtil` (managed-ledger) — `isAckSetEmpty` (1 site)
**Refactored `PositionAckSetUtil`**:
- `andAckSet(long[], long[])` now delegates to `AckSetUtil.intersect` —
eliminates two `BitSetRecyclable` allocs
- `isAckSetOverlap` rewritten with bitwise ops: a bit of `0` means *acked*;
overlap exists when any position is acked in both sets, i.e. `~(a[i] | b[i]) !=
0` for some word pair — eliminates two `BitSetRecyclable` allocs plus two full
`flip` passes
**Tests**: dedicated `AckSetUtilTest` with full coverage of all three
methods (empty arrays, all-zero, all-set, mixed, asymmetric lengths,
no/full/partial overlap).
### Verifying this change
- [x] Make sure that the change passes the CI checks.
```bash
# Unit tests
./gradlew :pulsar-common:test --tests
org.apache.pulsar.common.util.AckSetUtilTest
./gradlew :pulsar-common:test --tests
org.apache.pulsar.common.util.collections.BitSetRecyclableRecyclableTest
# Compilation
./gradlew :pulsar-common:compileJava :pulsar-common:compileTestJava \
:pulsar-broker:compileJava :managed-ledger:compileJava
# Style
./gradlew :pulsar-common:checkstyleMain :pulsar-common:checkstyleTest \
:pulsar-broker:checkstyleMain :managed-ledger:checkstyleMain
```
### Does this pull request potentially affect one of the following parts:
- [ ] Dependencies (add or upgrade a dependency)
- [ ] The public API
- [ ] The schema
- [ ] The default values of configurations
- [ ] The threading model
- [ ] The binary protocol
- [ ] The REST endpoints
- [ ] The admin CLI options
- [ ] The metrics
- [ ] Anything that affects deployment
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]