Skip to content

Commit 3929b82

Browse files
bugmakerrrrrrgf2121
authored andcommitted
Compute the doc range more efficiently when flushing doc block (#14447)
1 parent 3ab165c commit 3929b82

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Optimizations
3737

3838
* GITHUB#14333: Introduce a specialized trie for block tree index, instead of FST. (Guo Feng)
3939

40+
* GITHUB#14447: Compute the doc range more efficiently when flushing doc block. (Pan Guixin)
41+
4042
Bug Fixes
4143
---------------------
4244
(No changes)

lucene/core/src/java/org/apache/lucene/codecs/lucene103/Lucene103PostingsWriter.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,12 +429,13 @@ private void flushDocBlock(boolean finishTerm) throws IOException {
429429
// storage-efficient than the next number of bits per value (which effectively slightly biases
430430
// towards the bit set approach).
431431
int bitsPerValue = forDeltaUtil.bitsRequired(docDeltaBuffer);
432-
int sum = Math.toIntExact(Arrays.stream(docDeltaBuffer).sum());
433-
int numBitSetLongs = FixedBitSet.bits2words(sum);
432+
int docRange = lastDocID - level0LastDocID;
433+
assert docRange == Arrays.stream(docDeltaBuffer).sum();
434+
int numBitSetLongs = FixedBitSet.bits2words(docRange);
434435
int numBitsNextBitsPerValue = Math.min(Integer.SIZE, bitsPerValue + 1) * BLOCK_SIZE;
435-
if (sum == BLOCK_SIZE) {
436+
if (docRange == BLOCK_SIZE) {
436437
level0Output.writeByte((byte) 0);
437-
} else if (numBitsNextBitsPerValue <= sum) {
438+
} else if (numBitsNextBitsPerValue <= docRange) {
438439
level0Output.writeByte((byte) bitsPerValue);
439440
forDeltaUtil.encodeDeltas(bitsPerValue, docDeltaBuffer, level0Output);
440441
} else {

0 commit comments

Comments
 (0)