Xuliang0317 patch 1#8287
Open
xuliang0317 wants to merge 2 commits into
Open
Conversation
Removed the static bit-value lookup array and updated the checkBit method to use bitwise operations directly.
bit operations replace array
Author
|
@Apache9 Could you review this PR when you get a chance? |
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.
Optimize Bloom Filter bit operations by replacing array lookup with bitwise shift
While this is functional, it introduces unnecessary overhead in the read path, which is highly performance-sensitive:
Array Bounds Checking: The JVM must perform bounds checking for every array access to prevent ArrayIndexOutOfBoundsException, which adds minor but cumulative overhead.
Memory Access: Even though bitvals is likely cached in L1/L2 CPU cache, it still requires a memory load instruction.
Division/Modulo Overhead: In BloomFilterChunk#set(long pos), the code uses / 8 and % 8 which compiles to relatively expensive division instructions.
Solution
This PR optimizes the Bloom Filter bit operations by replacing the array lookup with direct bitwise shifts and optimizing the division/modulo operations:
Direct Bitwise Shift: Replaced BloomFilterUtil.bitvals[bitPos] with (1 << bitPos).
This eliminates array bounds checks completely.
The JIT compiler can optimize 1 << bitPos into a single, extremely fast CPU instruction (SHL), executing entirely within CPU registers with zero memory access latency.
Remove Unused Array: Removed the BloomFilterUtil.bitvals array completely to clean up the code.
Division to Shift Optimization: In BloomFilterChunk#set(long pos), replaced pos / 8 and pos % 8 with pos >> 3 and pos & 7. Since pos is always non-negative in this context, this is a safe and much faster alternative to division instructions.
Proposed Changes(去掉了不必要的数组,改成了位运算)