Replace AtomicLong with LongAdder in HitsThresholdChecker (#13546)

The value for the global count is incremented a lot more than it is
read, the space overhead of LongAdder seems irrelevant => lets use
LongAdder. The performance gain from using it is the higher the more
threads you use, but at 4 threads already very visible in benchmarks.
This commit is contained in:
Armin Braun 2024-07-08 10:52:28 +02:00 committed by GitHub
parent 62e08f5f4b
commit 2a8d328ab2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 4 deletions

View File

@ -17,13 +17,13 @@
package org.apache.lucene.search;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.LongAdder;
/** Used for defining custom algorithms to allow searches to early terminate */
abstract class HitsThresholdChecker {
/** Implementation of HitsThresholdChecker which allows global hit counting */
private static class GlobalHitsThresholdChecker extends HitsThresholdChecker {
private final AtomicLong globalHitCount = new AtomicLong();
private final LongAdder globalHitCount = new LongAdder();
GlobalHitsThresholdChecker(int totalHitsThreshold) {
super(totalHitsThreshold);
@ -32,12 +32,12 @@ abstract class HitsThresholdChecker {
@Override
void incrementHitCount() {
globalHitCount.incrementAndGet();
globalHitCount.increment();
}
@Override
boolean isThresholdReached() {
return globalHitCount.getAcquire() > getHitsThreshold();
return globalHitCount.longValue() > getHitsThreshold();
}
@Override