mikemccand commented on code in PR #13149: URL: https://github.com/apache/lucene/pull/13149#discussion_r1517878022
########## 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: > 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. Yeah indeed DISI may not be right, but let's not try to fix that here/now? Perhaps there are use cases that might want to call `.advance` on the DISI? Maybe some sort of curious combined filtering / points query? OK you convinced me!: let's leave the method as is. You're right that if such a use case existed today, it is suffering through the linear scan of `.visit` calls already, so this is no worse. -- 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