From 5b87a31556a5b3da7b5b1bafbabdb186dbd0b2da Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Thu, 2 Nov 2023 14:16:11 +0100 Subject: [PATCH] Speed up sorting on unique string fields. (#11903) Since increasing the number of hits retrieved in nightly benchmarks from 10 to 100, the performance of sorting documents by title dropped back to the level it had before introducing dynamic pruning. This is not too surprising given that the `title` field is a unique field, so the optimization would only kick in when the current 100th hit would have an ordinal that is less than 128 - something that would only happen after collecting most hits. This change increases the threshold to 1024, so that the optimization would kick in when the current 100th hit has an ordinal that is less than 1024, something that happens a bit sooner. --- lucene/CHANGES.txt | 2 ++ .../apache/lucene/search/comparators/TermOrdValComparator.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 09e34a55e3e..953e1b1cbb9 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -253,6 +253,8 @@ Optimizations * GITHUB#12719: Top-level conjunctions that are not sorted by score now have a specialized bulk scorer. (Adrien Grand) +* GITHUB#11903: Faster sort on high-cardinality string fields. (Adrien Grand) + Changes in runtime behavior --------------------- diff --git a/lucene/core/src/java/org/apache/lucene/search/comparators/TermOrdValComparator.java b/lucene/core/src/java/org/apache/lucene/search/comparators/TermOrdValComparator.java index 548bbb401b2..616b8cf7a7b 100644 --- a/lucene/core/src/java/org/apache/lucene/search/comparators/TermOrdValComparator.java +++ b/lucene/core/src/java/org/apache/lucene/search/comparators/TermOrdValComparator.java @@ -475,7 +475,7 @@ public class TermOrdValComparator extends FieldComparator { private class CompetitiveIterator extends DocIdSetIterator { - private static final int MAX_TERMS = 128; + private static final int MAX_TERMS = 1024; private final LeafReaderContext context; private final int maxDoc;