Conversation
Assisted-by: Codex
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
Managed-ledger range reads currently allocate three coordination objects for every successful read batch: the read callback, an
AtomicIntegerthat counts retained entries, and a capturingRunnableattached to every returned entry. These short-lived allocations add GC pressure on the persistent-topic read path.Modifications
Make the private read callback also own the atomic remaining-entry field and implement
Runnable. Every returned entry can then share that callback directly as its deallocation hook.The callback uses a terminal counter state to make successful or failed completion idempotent. It clears the forwarded callback after delivery, including when that callback throws, so entries retained by a consumer do not retain the dispatcher callback and its object graph. Read permits continue to be released exactly once after the final entry is deallocated, or immediately for an empty or failed read.
Verifying this change
A focused JMH benchmark covering real entry copies, deallocation hooks, and inflight-read permit accounting measured 40 fewer allocated bytes per batch for batch sizes 1, 100, and 1,000. CPU confidence intervals overlap, so this change does not claim a CPU improvement.
An end-to-end saturation screen sent five million keyed messages through 500 producers to five Key_Shared subscriptions with ten consumers each. Every subscription received all five million messages with zero duplicates, ordering violations, or invalid messages. The candidate completed at 66,192 msg/s and the immediately following baseline at 56,517 msg/s; this workload has substantial run-to-run variation, so the comparison is used only to exclude a material regression.
Validation:
RangeEntryCacheImplTestInflightReadsLimiterIntegrationTest./gradlew quickCheck./gradlew spotlessCheck checkstyleMain checkstyleTest