msokolov commented on code in PR #14674: URL: https://github.com/apache/lucene/pull/14674#discussion_r2112296471
########## lucene/core/src/java/org/apache/lucene/search/AbstractKnnVectorQuery.java: ########## @@ -226,15 +227,25 @@ private BitSet createBitSet(DocIdSetIterator iterator, Bits liveDocs, int maxDoc // If we already have a BitSet and no deletions, reuse the BitSet return bitSetIterator.getBitSet(); } else { - // Create a new BitSet from matching and live docs - FilteredDocIdSetIterator filterIterator = - new FilteredDocIdSetIterator(iterator) { - @Override - protected boolean match(int doc) { - return liveDocs == null || liveDocs.get(doc); - } - }; - return BitSet.of(filterIterator, maxDoc); + int threshold = maxDoc >> 7; // same as BitSet#of + if (iterator.cost() >= threshold) { + // take advantage of Disi#intoBitset and Bits#applyMask + FixedBitSet bitSet = new FixedBitSet(maxDoc); + bitSet.or(iterator); + if (liveDocs != null) { + liveDocs.applyMask(bitSet, 0); + } + return bitSet; + } else { + FilteredDocIdSetIterator filterIterator = + new FilteredDocIdSetIterator(iterator) { + @Override + protected boolean match(int doc) { + return liveDocs == null || liveDocs.get(doc); Review Comment: if `liveDocs == null` we could return `Bitset.of(iterator, maxDoc)`, no, and avoid the internal logic in the filtered iterator, which probably goes away with branch prediction :shrug: -- 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