[improve][client] Avoid recomputing entry-bucket hashes - #26383
Open
3pacccccc wants to merge 1 commit into
Open
Conversation
Entry-bucket batching already computes each message's entry-bucket hash to select its bucket. Recomputing the hash for every message while building the send operation duplicated that work on every flush. Maintain the batch's entry-hash minimum and maximum while messages are added, pass the already-computed hash into the batch container, and stamp metadata from the maintained range. Add a unit test for range maintenance and reset. 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
Entry-bucket batching already computes each message's entry-bucket hash when it selects the bucket for that message. However, while building the batch send operation,
BatchMessageContainerImpl#createOpSendMsg()recomputedthe same hash for every message in the batch in order to stamp
entry_hash_minandentry_hash_max.This means the hash of each message was calculated twice during the batching path:
EntryBucketBatchContainer#add()for bucket selection;BatchMessageContainerImpl#createOpSendMsg()for metadata stamping.For producers using entry-bucket batching, this duplicated hashing work on every batch flush and made the hashing cost proportional to the batch size twice instead of once.
Modifications
Compute the entry-bucket hash once in
EntryBucketBatchContainer#add().Pass that already-computed hash to
BatchMessageContainerImplthrough a package-private overload:Maintain the batch-level entry-bucket hash minimum and maximum incrementally while messages are added.
Replace the previous hash function field with a boolean flag indicating whether entry-bucket hash stamping is enabled.
Stamp entry_hash_min and entry_hash_max from the maintained minimum and maximum values instead of recomputing hashes for all messages.
Reset the maintained minimum and maximum values when the batch container is cleared.
Fail fast if the two-argument add() method is used on a container that requires a precomputed entry-bucket hash.
Add unit tests covering:
The additional add() overload is package-private on a package-private implementation class and is only used by EntryBucketBatchContainer; it does not change the public client API.
Verifying this change
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Matching PR in forked repository
PR in forked repository: 3pacccccc#39