[improve][broker] Part 2: Pack PendingAcksMap values into long#26030
Open
void-ptr974 wants to merge 6 commits into
Open
[improve][broker] Part 2: Pack PendingAcksMap values into long#26030void-ptr974 wants to merge 6 commits into
void-ptr974 wants to merge 6 commits into
Conversation
2 tasks
Contributor
Author
|
After this PR is merged, the next PR will switch the per-ledger entry map in That follow-up will keep the packed-value shape from this PR and focus only on removing the boxed inner-map key/value overhead. The BitSet prefix index for same-ledger |
merlimat
approved these changes
Jun 14, 2026
…alue-part2 # Conflicts: # pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PendingAcksMap.java # pulsar-broker/src/test/java/org/apache/pulsar/broker/service/PendingAcksMapTest.java
lhotari
requested changes
Jun 15, 2026
lhotari
left a comment
Member
There was a problem hiding this comment.
Related to #26028 (review). I have the fastutil minification working now and this change can be implemented on top of fastutil once the restoration of fastutil has been merged.
…alue-part2 # Conflicts: # pulsar-broker/src/main/java/org/apache/pulsar/broker/service/PendingAcksMap.java
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Part of #26027.
PendingAcksMaptracks entries that have been dispatched to Shared and Key_Shared consumers but are not fully acknowledged yet. Before this PR, each pending entry stored its value as anIntIntPair:The consumer hot paths usually only need the remaining unacked count after a lookup or removal. Keeping a value object per pending entry increases retained heap, and returning
IntIntPairfrom those paths can create short-lived objects that are avoidable.Modifications
longwhile keeping the same outer/inner sorted-map layout and ledger/entry ordering.getRemainingUnackedremoveAndGetRemainingUnackedConsumerto use the primitive accessors for ack owner lookup, full ack completion, and redelivery removal.getandremoveAndGetmethods that returnIntIntPairfor compatibility, and mark the legacy pair-returning path as deprecated.PendingAcksMapPackingBenchmarkundermicrobenchso this value-layout change can be measured independently from later inner-map changes.This PR only changes the value representation and the hot-path accessors. It does not replace the inner ordered map and does not include the later primitive hash-map or BitSet cleanup-index work.
Correctness coverage
PendingAcksMapTestcovers the updated behavior:updateRemainingUnackedremoveAllUpTocallback value preservationBenchmark
This PR adds
PendingAcksMapPackingBenchmark, which compares the value layout before this PR with the value layout introduced by this PR, using the same ledger/entry ordering behavior in both cases. The table below reports the before/after results relevant to this PR.Run command:
./gradlew :microbench:shadowJar java -jar microbench/build/libs/microbench-5.0.0-M1-SNAPSHOT-benchmarks.jar \ 'PendingAcksMapPackingBenchmark\..*' \ -p entries=50000 \ -p ledgers=1 \ -wi 1 -i 3 -w 1s -r 1s -f 1 \ -bm avgt -tu ns -prof gcLocal OpenJDK 25.0.2 results:
addOrReplacecontainsHitgetRemainingUnackedHitupdateRemainingUnackedremoveAndGetRemainingAndAddremoveWithValueAndAddforEachScanremoveAllUpToSmallPrefixAndRefillThe main effect is lower retained heap from removing one value object per pending entry, plus lower allocation on update/remove paths that no longer need to create replacement pair values. The legacy pair-returning methods remain available for compatibility.
JOL
GraphLayout.totalSize()on the value-layout change alone:Verifying this change
./gradlew :pulsar-broker:test --tests org.apache.pulsar.broker.service.PendingAcksMapTest --max-workers=1 -PtestRetryCount=0./gradlew :pulsar-broker:checkstyleMain :pulsar-broker:checkstyleTest --max-workers=1./gradlew :microbench:compileJava --max-workers=1./gradlew :microbench:checkstyleMain --max-workers=1./gradlew :microbench:shadowJar --max-workers=1