antonha commented on code in PR #13149: URL: https://github.com/apache/lucene/pull/13149#discussion_r1515631535
########## lucene/core/src/java/org/apache/lucene/util/bkd/DocIdsWriter.java: ########## @@ -36,6 +36,66 @@ final class DocIdsWriter { private final int[] scratch; + private final ScratchDocIdSetIterator scratchDocIdSetIterator = new ScratchDocIdSetIterator(); + + /** + * DocIdSetIterator to be used to iterate over the scratch buffer. A single instance is reused to + * avoid re-allocating the object. The reset method should be called before each use with the + * count. + * + * <p>The main reason for existing is to be able to call the {@link + * IntersectVisitor#visit(DocIdSetIterator)} method rather than the {@link + * IntersectVisitor#visit(int)} method. This seems to make a difference in performance, probably + * due to fewer virtual calls then happening (once per read call rather than once per doc). + */ + private class ScratchDocIdSetIterator extends DocIdSetIterator { + + private int index = -1; + private int count = -1; + + @Override + public int docID() { + if (index < 0) { + return -1; + } + if (index >= count) { + return NO_MORE_DOCS; + } + return scratch[index]; + } + + @Override + public int nextDoc() throws IOException { + index++; + if (index >= count) { + return NO_MORE_DOCS; + } + return scratch[index]; + } + + @Override + public int advance(int target) throws IOException { + while (index < count && scratch[index] < target) { Review Comment: Maybe we don't need to - but I don't see why this would be scarier than advancing using the `nextDoc` method? But I might be missing something - if you'd like that change, I'll make it. It might be that a DISI is not the right interface for visiting docids within the BKD tree - but I'm guessing changing that would be larger and more controversial. For large segments the buffer size would almost always be 512 - but there would be a lot of buffers. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org