mirror of https://github.com/apache/lucene.git
GITHUB#13175: Stop double-checking priority queue inserts in some FacetCount classes (#13488)
* GITHUB#13175: Stop double-checking priority queue inserts Removing 2 cases of bottomX optimizations where insertWithOverflow already handles the check. Closes #13175 * Update CHANGES.txt --------- Co-authored-by: Jakub Slowinski <jslowins@amazon.com>
This commit is contained in:
parent
392ddc154f
commit
295c5d3576
|
@ -278,6 +278,8 @@ Optimizations
|
|||
|
||||
* GITHUB#12941: Don't preserve auxiliary buffer contents in LSBRadixSorter if it grows. (Stefan Vodita)
|
||||
|
||||
* GITHUB#13175: Stop double-checking priority queue inserts in some FacetCount classes. (Jakub Slowinski)
|
||||
|
||||
Changes in runtime behavior
|
||||
---------------------
|
||||
|
||||
|
|
|
@ -180,8 +180,6 @@ public class StringValueFacetCounts extends Facets {
|
|||
topN = Math.min(topN, cardinality);
|
||||
TopOrdAndIntQueue q = null;
|
||||
TopOrdAndIntQueue.OrdAndInt reuse = null;
|
||||
int bottomCount = 0;
|
||||
int bottomOrd = Integer.MAX_VALUE;
|
||||
int childCount = 0; // total number of labels with non-zero count
|
||||
|
||||
if (sparseCounts != null) {
|
||||
|
@ -189,7 +187,22 @@ public class StringValueFacetCounts extends Facets {
|
|||
childCount++; // every count in sparseValues should be non-zero
|
||||
int ord = sparseCount.key;
|
||||
int count = sparseCount.value;
|
||||
if (count > bottomCount || (count == bottomCount && ord < bottomOrd)) {
|
||||
if (q == null) {
|
||||
// Lazy init for sparse case:
|
||||
q = new TopOrdAndIntQueue(topN);
|
||||
}
|
||||
if (reuse == null) {
|
||||
reuse = (TopOrdAndIntQueue.OrdAndInt) q.newOrdAndValue();
|
||||
}
|
||||
reuse.ord = ord;
|
||||
reuse.value = count;
|
||||
reuse = (TopOrdAndIntQueue.OrdAndInt) q.insertWithOverflow(reuse);
|
||||
}
|
||||
} else if (denseCounts != null) {
|
||||
for (int i = 0; i < denseCounts.length; i++) {
|
||||
int count = denseCounts[i];
|
||||
if (count != 0) {
|
||||
childCount++;
|
||||
if (q == null) {
|
||||
// Lazy init for sparse case:
|
||||
q = new TopOrdAndIntQueue(topN);
|
||||
|
@ -197,36 +210,9 @@ public class StringValueFacetCounts extends Facets {
|
|||
if (reuse == null) {
|
||||
reuse = (TopOrdAndIntQueue.OrdAndInt) q.newOrdAndValue();
|
||||
}
|
||||
reuse.ord = ord;
|
||||
reuse.ord = i;
|
||||
reuse.value = count;
|
||||
reuse = (TopOrdAndIntQueue.OrdAndInt) q.insertWithOverflow(reuse);
|
||||
if (q.size() == topN) {
|
||||
bottomCount = ((TopOrdAndIntQueue.OrdAndInt) q.top()).value;
|
||||
bottomOrd = q.top().ord;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (denseCounts != null) {
|
||||
for (int i = 0; i < denseCounts.length; i++) {
|
||||
int count = denseCounts[i];
|
||||
if (count != 0) {
|
||||
childCount++;
|
||||
if (count > bottomCount || (count == bottomCount && i < bottomOrd)) {
|
||||
if (q == null) {
|
||||
// Lazy init for sparse case:
|
||||
q = new TopOrdAndIntQueue(topN);
|
||||
}
|
||||
if (reuse == null) {
|
||||
reuse = (TopOrdAndIntQueue.OrdAndInt) q.newOrdAndValue();
|
||||
}
|
||||
reuse.ord = i;
|
||||
reuse.value = count;
|
||||
reuse = (TopOrdAndIntQueue.OrdAndInt) q.insertWithOverflow(reuse);
|
||||
if (q.size() == topN) {
|
||||
bottomCount = ((TopOrdAndIntQueue.OrdAndInt) q.top()).value;
|
||||
bottomOrd = q.top().ord;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -322,8 +322,6 @@ abstract class AbstractSortedSetDocValueFacetCounts extends Facets {
|
|||
private TopChildrenForPath computeTopChildren(
|
||||
PrimitiveIterator.OfInt childOrds, int topN, DimConfig dimConfig, int pathOrd) {
|
||||
TopOrdAndIntQueue q = null;
|
||||
int bottomCount = 0;
|
||||
int bottomOrd = Integer.MAX_VALUE;
|
||||
int pathCount = 0;
|
||||
int childCount = 0;
|
||||
|
||||
|
@ -334,23 +332,17 @@ abstract class AbstractSortedSetDocValueFacetCounts extends Facets {
|
|||
if (count > 0) {
|
||||
pathCount += count;
|
||||
childCount++;
|
||||
if (count > bottomCount || (count == bottomCount && ord < bottomOrd)) {
|
||||
if (q == null) {
|
||||
// Lazy init, so we don't create this for the
|
||||
// sparse case unnecessarily
|
||||
q = new TopOrdAndIntQueue(topN);
|
||||
}
|
||||
if (reuse == null) {
|
||||
reuse = (TopOrdAndIntQueue.OrdAndInt) q.newOrdAndValue();
|
||||
}
|
||||
reuse.ord = ord;
|
||||
reuse.value = count;
|
||||
reuse = (TopOrdAndIntQueue.OrdAndInt) q.insertWithOverflow(reuse);
|
||||
if (q.size() == topN) {
|
||||
bottomCount = ((TopOrdAndIntQueue.OrdAndInt) q.top()).value;
|
||||
bottomOrd = q.top().ord;
|
||||
}
|
||||
if (q == null) {
|
||||
// Lazy init, so we don't create this for the
|
||||
// sparse case unnecessarily
|
||||
q = new TopOrdAndIntQueue(topN);
|
||||
}
|
||||
if (reuse == null) {
|
||||
reuse = (TopOrdAndIntQueue.OrdAndInt) q.newOrdAndValue();
|
||||
}
|
||||
reuse.ord = ord;
|
||||
reuse.value = count;
|
||||
reuse = (TopOrdAndIntQueue.OrdAndInt) q.insertWithOverflow(reuse);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue