From c30bb6f3ae3c74061c4dd917b92a1f0bc8d74b94 Mon Sep 17 00:00:00 2001 From: Greg Miller Date: Fri, 16 Aug 2024 10:13:43 -0700 Subject: [PATCH] inline the call to createWeight to even more tightly isolate the regression --- .../apache/lucene/search/IndexSearcher.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java index bf8c8467b2a..4b09de7091b 100644 --- a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java +++ b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java @@ -631,12 +631,28 @@ public class IndexSearcher { public T search(Query query, CollectorManager collectorManager) throws IOException { final C firstCollector = collectorManager.newCollector(); - query = rewrite(query, firstCollector.scoreMode().needsScores()); - // Initializing `collectors` here (before createWeight) causes regression... + final ScoreMode scoreMode = firstCollector.scoreMode(); + query = rewrite(query, scoreMode.needsScores()); + + //////// + // Inlining the createWeight method... + + // Initializing `collectors` here (before query.createWeight) causes regression... final List collectors = new ArrayList<>(8); - final Weight weight = createWeight(query, firstCollector.scoreMode(), 1); + + Weight weight = query.createWeight(this, scoreMode, 1); + // ... but if we move the initialization here, there is no impact. // final List collectors = new ArrayList<>(8); + + final QueryCache queryCache = this.queryCache; + if (scoreMode.needsScores() == false && queryCache != null) { + weight = queryCache.doCache(weight, queryCachingPolicy); + } + + // ...end inlining of createWeight method + //////// + return search(weight, collectorManager, firstCollector, collectors); }