Apache Lucene open-source search software
Adding benchmark for histogram collector over point range query (#14622)
Ankit Jain22279df74717
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex fd84ae0201a..843253bf167 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -94,7 +94,7 @@ Optimizations---------------------* GITHUB#14418: Quick exit on filter query matching no docs when rewriting knn query. (Pan Guixin)-* GITHUB#14439, GITHUB#14560: Efficient Histogram Collection using multi range traversal over PointTrees (Ankit Jain)+* GITHUB#14439, GITHUB#14560, GITHUB#14622: Efficient Histogram Collection using multi range traversal over PointTrees (Ankit Jain)* GITHUB#14268: PointInSetQuery early exit on non-matching segments. (hanbj)diff --git a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/HistogramCollectorBenchmark.java b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/HistogramCollectorBenchmark.javaindex 4cc9c08833c..86b2ccc2f17 100644--- a/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/HistogramCollectorBenchmark.java+++ b/lucene/benchmark-jmh/src/java/org/apache/lucene/benchmark/jmh/HistogramCollectorBenchmark.java@@ -33,8 +33,10 @@ import org.apache.lucene.index.IndexWriterConfig;import org.apache.lucene.sandbox.facet.plain.histograms.HistogramCollectorManager;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.MatchAllDocsQuery;+import org.apache.lucene.search.PointRangeQuery;import org.apache.lucene.store.Directory;import org.apache.lucene.store.MMapDirectory;+import org.apache.lucene.util.NumericUtils;import org.openjdk.jmh.annotations.Benchmark;import org.openjdk.jmh.annotations.BenchmarkMode;import org.openjdk.jmh.annotations.Fork;@@ -122,9 +124,40 @@ public class HistogramCollectorBenchmark {}@Benchmark- public void collectHistogram(BenchmarkParams params) throws IOException {+ public void matchAllQueryHistogram(BenchmarkParams params) throws IOException {IndexSearcher searcher = new IndexSearcher(reader);searcher.search(new MatchAllDocsQuery(), new HistogramCollectorManager("f", params.bucketWidth, 10000));}++ @Benchmark+ public void pointRangeQueryHistogram(BenchmarkParams params) throws IOException {+ IndexSearcher searcher = new IndexSearcher(reader);++ Random r = new Random(0);+ int lowerBound = r.nextInt(params.docCount / 4, 3 * params.docCount / 4);+ // Filter for about 1/10 of the available documents+ int upperBound = lowerBound + params.docCount / 10;++ if (params.pointEnabled) {+ byte[] lowerPoint = new byte[Long.BYTES];+ byte[] upperPoint = new byte[Long.BYTES];+ NumericUtils.longToSortableBytes(lowerBound, lowerPoint, 0);+ NumericUtils.longToSortableBytes(upperBound, upperPoint, 0);+ final PointRangeQuery prq =+ new PointRangeQuery("f", lowerPoint, upperPoint, 1) {+ @Override+ protected String toString(int dimension, byte[] value) {+ return Long.toString(NumericUtils.sortableBytesToLong(value, 0));+ }+ };++ // Don't need to increase the default bucket count+ searcher.search(prq, new HistogramCollectorManager("f", params.bucketWidth));+ } else {+ searcher.search(+ NumericDocValuesField.newSlowRangeQuery("f", lowerBound, upperBound),+ new HistogramCollectorManager("f", params.bucketWidth));+ }+ }}diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/facet/plain/histograms/PointTreeBulkCollector.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/facet/plain/histograms/PointTreeBulkCollector.javaindex 0d664d27e58..8e8f9403046 100644--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/facet/plain/histograms/PointTreeBulkCollector.java+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/facet/plain/histograms/PointTreeBulkCollector.java@@ -187,8 +187,11 @@ class PointTreeBulkCollector {}}- // Not possible to have the CELL_OUTSIDE_QUERY, as bucket lower bound is updated- // while finalizing the previous bucket+ // CELL_OUTSIDE_QUERY is possible for the first bucket+ // in case of PointRangeQuery [min, max] lower+ if (!collector.withinLowerBound(maxPackedValue)) {+ return PointValues.Relation.CELL_OUTSIDE_QUERY;+ }if (collector.withinRange(minPackedValue) && collector.withinRange(maxPackedValue)) {return PointValues.Relation.CELL_INSIDE_QUERY;}