Skip to content

Commit

Permalink
Speed up Lucene912PostingsReader nextDoc() impls. (#13963)
Browse files Browse the repository at this point in the history
127 times out of 128, nextDoc() returns the next doc ID in the buffer.
Currently, we check if the current doc is equal to the last doc ID in the block
to know if we need to refill. We can do better by comparing the current index
in the block with the block size, which is a bit more efficient since the
latter is a constant.
  • Loading branch information
jpountz authored Oct 29, 2024
1 parent 60ddd08 commit 9359cfd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ Optimizations

* GITHUB#13961: Replace Map<String,Object> with IntObjectHashMap for DV producer. (Pan Guixin)

* GITHUB#13963: Speed up nextDoc() implementations in Lucene912PostingsReader.
(Adrien Grand)

Bug Fixes
---------------------
* GITHUB#13832: Fixed an issue where the DefaultPassageFormatter.format method did not format passages as intended
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ private void moveToNextLevel0Block() throws IOException {

@Override
public int nextDoc() throws IOException {
if (doc == level0LastDocID) { // advance skip data on level 0
if (docBufferUpto == BLOCK_SIZE) { // advance skip data on level 0
moveToNextLevel0Block();
}

Expand Down Expand Up @@ -875,7 +875,7 @@ private void moveToNextLevel0Block() throws IOException {

@Override
public int nextDoc() throws IOException {
if (doc == level0LastDocID) { // advance level 0 skip data
if (docBufferUpto == BLOCK_SIZE) { // advance level 0 skip data
moveToNextLevel0Block();
}

Expand Down Expand Up @@ -1417,11 +1417,13 @@ private void moveToNextLevel0Block() throws IOException {

@Override
public int nextDoc() throws IOException {
if (doc == level0LastDocID) {
moveToNextLevel0Block();
} else if (needsRefilling) {
refillDocs();
needsRefilling = false;
if (docBufferUpto == BLOCK_SIZE) {
if (needsRefilling) {
refillDocs();
needsRefilling = false;
} else {
moveToNextLevel0Block();
}
}

return this.doc = (int) docBuffer[docBufferUpto++];
Expand Down Expand Up @@ -1644,8 +1646,9 @@ public void advanceShallow(int target) throws IOException {

@Override
public int nextDoc() throws IOException {
advanceShallow(doc + 1);
if (needsRefilling) {
if (docBufferUpto == BLOCK_SIZE) {
advanceShallow(doc + 1);
assert needsRefilling;
refillDocs();
needsRefilling = false;
}
Expand Down

0 comments on commit 9359cfd

Please sign in to comment.