Apache Lucene open-source search software
Further reduce the search concurrency overhead. (#13606)
Adrien Grandacbd7141404d
diff --git a/lucene/core/src/java/org/apache/lucene/search/HitsThresholdChecker.java b/lucene/core/src/java/org/apache/lucene/search/HitsThresholdChecker.javaindex 4232af53fe6..43ff4fecdbb 100644--- a/lucene/core/src/java/org/apache/lucene/search/HitsThresholdChecker.java+++ b/lucene/core/src/java/org/apache/lucene/search/HitsThresholdChecker.java@@ -24,6 +24,10 @@ abstract class HitsThresholdChecker {/** Implementation of HitsThresholdChecker which allows global hit counting */private static class GlobalHitsThresholdChecker extends HitsThresholdChecker {private final LongAdder globalHitCount = new LongAdder();+ // Cache whether the threshold has been reached already. It is not volatile or synchronized on+ // purpose to contain the overhead of reading the value similarly to what String#hashCode()+ // does. This does not affect correctness.+ private boolean thresholdReached = false;GlobalHitsThresholdChecker(int totalHitsThreshold) {super(totalHitsThreshold);@@ -32,12 +36,17 @@ abstract class HitsThresholdChecker {@Overridevoid incrementHitCount() {- globalHitCount.increment();+ if (thresholdReached == false) {+ globalHitCount.increment();+ }}@Overrideboolean isThresholdReached() {- return globalHitCount.longValue() > getHitsThreshold();+ if (thresholdReached) {+ return true;+ }+ return thresholdReached = globalHitCount.longValue() > getHitsThreshold();}@Override