Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-10516

reduce unnecessary loop matches in BKDReader

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 8.6.2
    • None
    • core/other
    • None
    • New

    Description

      In BKDReader.visitSparseRawDocValues(), we will read a batch of docIds which have the same point value:scratchPackedValue, then call visitor.visit(scratchIterator, scratchPackedValue) to find which docIDs match the range.

      default void visit(DocIdSetIterator iterator, byte[] packedValue) throws IOException {
            int docID;
            while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { 
              visit(docID, packedValue); 
            }
          }
      

      We know that the packedValue are same for the batch of docIds, if the first doc match the range, the batch of other docIds will also match the range, so the loop seems useless.

      We should call the method as follow:

                public void visit(DocIdSetIterator iterator, byte[] packedValue) throws IOException {
                  if (matches(packedValue)) {
                    int docID;
                    while ((docID = iterator.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
                      visit(docID);
                    }
                  }
                }
      

      https://github.com/apache/lucene/blob/2e941fcfed6cad3d9c8667ff5324cd04858ba547/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java#L196

      If we should override the visit(DocIdSetIterator iterator, byte[] packedValue) in ExitableDirectoryReader$ExitableIntersectVisitor to avoid calling the default implement:

              @Override
              public void visit(DocIdSetIterator iterator, byte[] packedValue) throws IOException {
                  queryCancellation.checkCancelled();
                  in.visit(iterator, packedValue);
              }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            kkewwei kkewwei
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: