jimczi commented on a change in pull request #1316: LUCENE-8929 parallel early termination in TopFieldCollector using minmin score URL: https://github.com/apache/lucene-solr/pull/1316#discussion_r394213103
########## File path: lucene/core/src/java/org/apache/lucene/search/ParallelSortedCollector.java ########## @@ -0,0 +1,612 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.lucene.search; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.PriorityQueue; + +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.search.FieldValueHitQueue.Entry; +import org.apache.lucene.search.TotalHits.Relation; + +/** + * A {@link Collector} for results sorted by field, optimized for early termination in + * the case where the {@link Sort} matches the index and the search is executed in parallel, + * using multiple threads. + * + * @lucene.experimental + */ Review comment: I wonder why it should be reserved for parallel collection ? Sorry I wasn't clear but I thought that specializing collectors for sorted index could open the door for more optimizations. For instance the priority queue is not needed since the index is already sorted, a lot of comparisons could be saved ? Regarding the usage of the `MaxScoreTerminator`, I think it would be simpler if the logic to track leaf state remains in the `LeafCollector`. We have to track the global bottom value but I don't understand why `MaxScoreTerminator` also handles leave states. This is similar to the `MaxScoreAccumulator` so you could apply the logic for termination directly in the collector: ```` if (hitsThresholdChecker.isThresholdReached() && Double.compare(maxScoreTerminator.getCurrent(), leafTerminationState) > 0)) { // should early terminated ```` Checking the current bottom score does not require extensive synchronization so the interval at which the bottom value is checked is more to avoid extra comparison than thread contention. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org