-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
HBASE-28025 Enhance ByteBufferUtils.findCommonPrefix to compare 8 bytes each time #5354
Merged
Apache9
merged 1 commit into
apache:master
from
jbewing:HBASE-28025-optimize-find-common-prefix-compare
Aug 20, 2023
Merged
HBASE-28025 Enhance ByteBufferUtils.findCommonPrefix to compare 8 bytes each time #5354
Apache9
merged 1 commit into
apache:master
from
jbewing:HBASE-28025-optimize-find-common-prefix-compare
Aug 20, 2023
Conversation
This file contains 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
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
🎊 +1 overall
This message was automatically generated. |
Apache9
approved these changes
Aug 17, 2023
Apache9
pushed a commit
that referenced
this pull request
Aug 20, 2023
…es each time (#5354) Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit dae078e)
Apache9
pushed a commit
that referenced
this pull request
Aug 20, 2023
…es each time (#5354) Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit dae078e)
Apache9
pushed a commit
that referenced
this pull request
Aug 20, 2023
…es each time (#5354) Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit dae078e)
Apache9
pushed a commit
that referenced
this pull request
Aug 20, 2023
…es each time (#5354) Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit dae078e)
bbeaudreault
pushed a commit
to HubSpot/hbase
that referenced
this pull request
Aug 21, 2023
…x to compare 8 bytes each time (apache#5354) Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit dae078e)
vinayakphegde
pushed a commit
to vinayakphegde/hbase
that referenced
this pull request
Apr 4, 2024
…es each time (apache#5354) Signed-off-by: Duo Zhang <[email protected]> (cherry picked from commit dae078e) (cherry picked from commit 6596ef6) Change-Id: I046c51b34f9cd6809df3e940b42f927e75fdc85f
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.
What
This PR updates
ByteBufferUtils#findCommonPrefix
andBytes#findCommonPrefix
to compare 8 bytes from the input buffers/arrays ifUnsafe
access is available. On platforms where Unsafe is unavailable, we use the current implementations. This is a similar optimization as to what is already done withByteBufferUtils#compareToUnsafe
.Implementation Notes
There was a
Bytes#findCommonPrefix
method and aByteBufferUtils#findCommonPrefix
method that both acceptedbyte[]
args. I've updated theByteBufferUtils#findCommonPrefix
method to delegate toBytes#findCommonPrefix
and applied the optimization for 8 byte at a time comparison to theBytes
class.Overall, the implementation draws a ton of inspiration from
ByteBufferUtils#compareToUnsafe
. The only large change that I made is for how we handle mismatches in the big endian case. I used the number of leading zeros intrinsic there instead of the number of trailing zeros intrinsic to find which byte was mismatched.Testing
I've added some unit tests to cover testing the path with unsafe enabled and disabled.
Benchmarking
I haven't done any micro-benchmarking of the new "faster" implementations vs. the current implementations. I'll update the JIRA with a link to those when I get a chance to write them. For now, I'm assuming that this method of finding common prefixes is faster than the current one based off the previous micro-benchmarking results forI've done some microbenchmarking with JMH. The results are in this JIRA commentcompareTo
(as this is very similar code).HBASE-28025