Eliminate redundant cardinality() pass in MaxScoreBulkScorer#15971
Open
iprithv wants to merge 2 commits intoapache:mainfrom
Open
Eliminate redundant cardinality() pass in MaxScoreBulkScorer#15971iprithv wants to merge 2 commits intoapache:mainfrom
iprithv wants to merge 2 commits intoapache:mainfrom
Conversation
Signed-off-by: prithvi <prithvisivasankar@gmail.com>
2aa8442 to
6c4804e
Compare
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.
Description
In
MaxScoreBulkScorer.scoreInnerWindowMultipleEssentialClauses(), thecardinality()call was used solely to pre-size thedocAndScoreAccBufferbefore extracting matches from the bitset viaforEach(). This resulted in two full passes over the bitset's 64 longs (forINNER_WINDOW_SIZE=4096): one for counting, one for extraction.This change replaces
growNoCopy(windowMatches.cardinality(0, innerWindowSize))withgrowNoCopy(INNER_WINDOW_SIZE), eliminating the counting pass entirely. The buffer is reused across inner windows, so the one-time over-allocation (~48KB forint[] + double[]) is negligible.Benchmark Results
JMH benchmark
5-13% improvement across typical match densities (50-500 docs per window), which is the common range for multi-term BooleanQuery workloads.
Context
This method is on the hot path for multi-clause BooleanQuery scoring:
IndexSearcher.search()→MaxScoreBulkScorer.score()→scoreInnerWindowMultipleEssentialClauses()It is invoked for every 4096-doc inner window when a query has 2+ essential clauses. The
cardinality()call was iterating all 64 longs of the bitset purely to determine a buffer size, work that can be avoided by pre-allocating to the maximum possible size.An
intoArray()- based approach was also evaluated but proved slower for sparse windows (10-128 matches) due to scanning empty words. TheforEach()approach with pre allocation is the best strategy across all densities.