mirror of https://github.com/apache/lucene.git
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:
parent
62e08f5f4b
commit
2a8d328ab2
|
@ -17,13 +17,13 @@
|
||||||
|
|
||||||
package org.apache.lucene.search;
|
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 */
|
/** Used for defining custom algorithms to allow searches to early terminate */
|
||||||
abstract class HitsThresholdChecker {
|
abstract class HitsThresholdChecker {
|
||||||
/** Implementation of HitsThresholdChecker which allows global hit counting */
|
/** Implementation of HitsThresholdChecker which allows global hit counting */
|
||||||
private static class GlobalHitsThresholdChecker extends HitsThresholdChecker {
|
private static class GlobalHitsThresholdChecker extends HitsThresholdChecker {
|
||||||
private final AtomicLong globalHitCount = new AtomicLong();
|
private final LongAdder globalHitCount = new LongAdder();
|
||||||
|
|
||||||
GlobalHitsThresholdChecker(int totalHitsThreshold) {
|
GlobalHitsThresholdChecker(int totalHitsThreshold) {
|
||||||
super(totalHitsThreshold);
|
super(totalHitsThreshold);
|
||||||
|
@ -32,12 +32,12 @@ abstract class HitsThresholdChecker {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void incrementHitCount() {
|
void incrementHitCount() {
|
||||||
globalHitCount.incrementAndGet();
|
globalHitCount.increment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isThresholdReached() {
|
boolean isThresholdReached() {
|
||||||
return globalHitCount.getAcquire() > getHitsThreshold();
|
return globalHitCount.longValue() > getHitsThreshold();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue