mirror of https://github.com/apache/lucene.git
Further reduce the search concurrency overhead. (#13606)
This iterates on #13546 to further reduce the overhead of search concurrency by caching whether the hit count threshold has been reached: once the threshold has been reached, it cannot get "un-reached" again, so we don't need to pay the cost of `LongAdder#longValue`.
This commit is contained in:
parent
97d066dd6b
commit
acbd714140
|
@ -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 {
|
|||
|
||||
@Override
|
||||
void incrementHitCount() {
|
||||
globalHitCount.increment();
|
||||
if (thresholdReached == false) {
|
||||
globalHitCount.increment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean isThresholdReached() {
|
||||
return globalHitCount.longValue() > getHitsThreshold();
|
||||
if (thresholdReached) {
|
||||
return true;
|
||||
}
|
||||
return thresholdReached = globalHitCount.longValue() > getHitsThreshold();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue