You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2019/06/10 14:00:57 UTC

[lucene-solr] 01/03: LUCENE-8834: Cache the SortedNumericDocValues.docValueCount() value whenever it is used in a loop (#698)

This is an automated email from the ASF dual-hosted git repository.

jpountz pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 1e49d84545e6393768fd11873245351e129405a4
Author: Tim Underwood <ti...@gmail.com>
AuthorDate: Sun Jun 9 23:56:21 2019 -0700

    LUCENE-8834: Cache the SortedNumericDocValues.docValueCount() value whenever it is used in a loop (#698)
---
 lucene/join/src/java/org/apache/lucene/search/join/JoinUtil.java     | 2 +-
 .../org/apache/solr/handler/component/SortedDateStatsValues.java     | 2 +-
 .../org/apache/solr/handler/component/SortedNumericStatsValues.java  | 2 +-
 .../src/java/org/apache/solr/handler/export/MultiFieldWriter.java    | 2 +-
 solr/core/src/java/org/apache/solr/request/IntervalFacets.java       | 5 +++--
 solr/core/src/java/org/apache/solr/request/NumericFacets.java        | 2 +-
 solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java   | 5 +++--
 .../org/apache/solr/search/facet/FacetFieldProcessorByHashDV.java    | 2 +-
 solr/core/src/java/org/apache/solr/search/facet/HLLAgg.java          | 2 +-
 solr/core/src/java/org/apache/solr/search/facet/UniqueAgg.java       | 2 +-
 10 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/lucene/join/src/java/org/apache/lucene/search/join/JoinUtil.java b/lucene/join/src/java/org/apache/lucene/search/join/JoinUtil.java
index 3f17d07..0e933c0 100644
--- a/lucene/join/src/java/org/apache/lucene/search/join/JoinUtil.java
+++ b/lucene/join/src/java/org/apache/lucene/search/join/JoinUtil.java
@@ -200,7 +200,7 @@ public final class JoinUtil {
         @Override
         public void collect(int doc) throws IOException {
           if (sortedNumericDocValues.advanceExact(doc)) {
-            for (int i = 0; i < sortedNumericDocValues.docValueCount(); i++) {
+            for (int i = 0, count = sortedNumericDocValues.docValueCount(); i < count; i++) {
               long value = sortedNumericDocValues.nextValue();
               joinValues.add(value);
               if (needsScore) {
diff --git a/solr/core/src/java/org/apache/solr/handler/component/SortedDateStatsValues.java b/solr/core/src/java/org/apache/solr/handler/component/SortedDateStatsValues.java
index 0df45c7..9e6076f 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/SortedDateStatsValues.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/SortedDateStatsValues.java
@@ -49,7 +49,7 @@ public class SortedDateStatsValues implements StatsValues {
     if (!sndv.advanceExact(docId)) {
       missing();
     } else {
-      for (int i = 0 ; i < sndv.docValueCount(); i++) {
+      for (int i = 0, count = sndv.docValueCount(); i < count; i++) {
         dsv.accumulate(new Date(sndv.nextValue()), 1);
       }
     }
diff --git a/solr/core/src/java/org/apache/solr/handler/component/SortedNumericStatsValues.java b/solr/core/src/java/org/apache/solr/handler/component/SortedNumericStatsValues.java
index 007fb28..91b313d 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/SortedNumericStatsValues.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/SortedNumericStatsValues.java
@@ -51,7 +51,7 @@ public class SortedNumericStatsValues implements StatsValues {
     if (!sndv.advanceExact(docId)) {
       missing();
     } else {
-      for (int i = 0 ; i < sndv.docValueCount(); i++) {
+      for (int i = 0, count = sndv.docValueCount(); i < count; i++) {
         nsv.accumulate(toCorrectType(sndv.nextValue()), 1);
       }
     }
diff --git a/solr/core/src/java/org/apache/solr/handler/export/MultiFieldWriter.java b/solr/core/src/java/org/apache/solr/handler/export/MultiFieldWriter.java
index 72135b5..ae4a6cd 100644
--- a/solr/core/src/java/org/apache/solr/handler/export/MultiFieldWriter.java
+++ b/solr/core/src/java/org/apache/solr/handler/export/MultiFieldWriter.java
@@ -60,7 +60,7 @@ class MultiFieldWriter extends FieldWriter {
       if (!vals.advanceExact(sortDoc.docId)) return false;
       out.put(this.field,
           (IteratorWriter) w -> {
-            for (int i = 0; i < vals.docValueCount(); i++) {
+            for (int i = 0, count = vals.docValueCount(); i < count; i++) {
               w.add(bitsToValue.apply(vals.nextValue()));
             }
           });
diff --git a/solr/core/src/java/org/apache/solr/request/IntervalFacets.java b/solr/core/src/java/org/apache/solr/request/IntervalFacets.java
index c2d6ab0..6e492e7 100644
--- a/solr/core/src/java/org/apache/solr/request/IntervalFacets.java
+++ b/solr/core/src/java/org/apache/solr/request/IntervalFacets.java
@@ -310,9 +310,10 @@ public class IntervalFacets implements Iterable<FacetInterval> {
   private void accumIntervalWithMultipleValues(SortedNumericDocValues longs) throws IOException {
     // longs should be already positioned to the correct doc
     assert longs.docID() != -1;
-    assert longs.docValueCount() > 0: "Should have at least one value for this document";
+    final int docValueCount = longs.docValueCount();
+    assert docValueCount > 0: "Should have at least one value for this document";
     int currentInterval = 0;
-    for (int i = 0; i < longs.docValueCount(); i++) {
+    for (int i = 0; i < docValueCount; i++) {
       boolean evaluateNextInterval = true;
       long value = longs.nextValue();
       while (evaluateNextInterval && currentInterval < intervals.length) {
diff --git a/solr/core/src/java/org/apache/solr/request/NumericFacets.java b/solr/core/src/java/org/apache/solr/request/NumericFacets.java
index b509995..4ef9f26 100644
--- a/solr/core/src/java/org/apache/solr/request/NumericFacets.java
+++ b/solr/core/src/java/org/apache/solr/request/NumericFacets.java
@@ -436,7 +436,7 @@ final class NumericFacets {
       if (valuesDocID == doc - ctx.docBase) {
         long l = longs.nextValue(); // This document must have at least one value
         hashTable.add(l, 1);
-        for (int i = 1; i < longs.docValueCount(); i++) {
+        for (int i = 1, count = longs.docValueCount(); i < count; i++) {
           long lnew = longs.nextValue();
           if (lnew > l) { // Skip the value if it's equal to the last one, we don't want to double-count it
             hashTable.add(lnew, 1);
diff --git a/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java b/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java
index 4d5018d..b1c17be 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrDocumentFetcher.java
@@ -554,8 +554,9 @@ public class SolrDocumentFetcher {
       case SORTED_NUMERIC:
         final SortedNumericDocValues numericDv = leafReader.getSortedNumericDocValues(fieldName);
         if (numericDv != null && numericDv.advance(localId) == localId) {
-          final List<Object> outValues = new ArrayList<>(numericDv.docValueCount());
-          for (int i = 0; i < numericDv.docValueCount(); i++) {
+          final int docValueCount = numericDv.docValueCount();
+          final List<Object> outValues = new ArrayList<>(docValueCount);
+          for (int i = 0; i < docValueCount; i++) {
             long number = numericDv.nextValue();
             Object value = decodeNumberFromDV(schemaField, number, true);
             // return immediately if the number is not decodable, hence won't return an empty list.
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetFieldProcessorByHashDV.java b/solr/core/src/java/org/apache/solr/search/facet/FacetFieldProcessorByHashDV.java
index 38feddd..42d23ef 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetFieldProcessorByHashDV.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetFieldProcessorByHashDV.java
@@ -387,7 +387,7 @@ class FacetFieldProcessorByHashDV extends FacetFieldProcessor {
             if (values.advanceExact(segDoc)) {
               long l = values.nextValue(); // This document must have at least one value
               collectValFirstPhase(segDoc, l);
-              for (int i = 1; i < values.docValueCount(); i++) {
+              for (int i = 1, count = values.docValueCount(); i < count; i++) {
                 long lnew = values.nextValue();
                 if (lnew != l) { // Skip the value if it's equal to the last one, we don't want to double-count it
                   collectValFirstPhase(segDoc, lnew);
diff --git a/solr/core/src/java/org/apache/solr/search/facet/HLLAgg.java b/solr/core/src/java/org/apache/solr/search/facet/HLLAgg.java
index 4634bc2..49d1213 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/HLLAgg.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/HLLAgg.java
@@ -237,7 +237,7 @@ public class HLLAgg extends StrAggValueSource {
 
     @Override
     protected void collectValues(int doc, HLL hll) throws IOException {
-      for (int i = 0; i < values.docValueCount(); i++) {
+      for (int i = 0, count = values.docValueCount(); i < count; i++) {
         // duplicates may be produced for a single doc, but won't matter here.
         long val = values.nextValue();
         long hash = Hash.fmix64(val);
diff --git a/solr/core/src/java/org/apache/solr/search/facet/UniqueAgg.java b/solr/core/src/java/org/apache/solr/search/facet/UniqueAgg.java
index 5d9cf90..3df9c9e 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/UniqueAgg.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/UniqueAgg.java
@@ -254,7 +254,7 @@ public class UniqueAgg extends StrAggValueSource {
 
     @Override
     protected void collectValues(int doc, LongSet set) throws IOException {
-      for (int i = 0; i < values.docValueCount(); i++) {
+      for (int i = 0, count = values.docValueCount(); i < count; i++) {
         // duplicates may be produced for a single doc, but won't matter here.
         set.add(values.nextValue());
       }