You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2025/12/08 08:40:26 UTC

(lucene) branch branch_10x updated: Skip heavy TreeSet opts for the first group in FirstPassGroupingCollector (#15128)

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

dweiss pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_10x by this push:
     new d4c04a75a10 Skip heavy TreeSet opts for the first group in FirstPassGroupingCollector (#15128)
d4c04a75a10 is described below

commit d4c04a75a108cbfceefdda2f89bfeb759ca0ce0f
Author: gaobinlong <gb...@amazon.com>
AuthorDate: Mon Dec 8 16:29:40 2025 +0800

    Skip heavy TreeSet opts for the first group in FirstPassGroupingCollector (#15128)
    
    * Skip heavy TreeSet opts for first/last group in FirstPassGroupingCollector
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
    
    * Add change log
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
    
    * Only skip remove/add for first group
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
    
    * Modify change log
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
    
    * Merge two if condition
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
    
    * Modify change log
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
    
    ---------
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
---
 lucene/CHANGES.txt                                  |  2 ++
 .../search/grouping/FirstPassGroupingCollector.java | 21 ++++++++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 5e5dcd6fe39..94a853d1407 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -79,6 +79,8 @@ Optimizations
 * GITHUB#15151: Use `SimScorer#score` bulk API to compute impact scores per
   block of postings. (Adrien Grand)
 
+* GITHUB#15128: Skip heavy TreeSet opts for the first group in FirstPassGroupingCollector (Binlong Gao)
+
 * GITHUB#15167: FirstPassGroupingCollector supports ignoring docs without group field (Binlong Gao)
 
 * GITHUB#15160: Increased the size used for blocks of postings from 128 to 256.
diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java
index 0a123adb630..67ca0bbe20e 100644
--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java
+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java
@@ -317,14 +317,19 @@ public class FirstPassGroupingCollector<T> extends SimpleCollector {
       }
     }
 
-    // Remove before updating the group since lookup is done via comparators
-    // TODO: optimize this
-
     final CollectedSearchGroup<T> prevLast;
+    boolean skipHeavyOps = false;
+
     if (orderedGroups != null) {
       prevLast = orderedGroups.last();
-      orderedGroups.remove(group);
-      assert orderedGroups.size() == topNGroups - 1;
+
+      // Skip remove/add for first group
+      if (group == orderedGroups.first()) {
+        skipHeavyOps = true;
+      } else {
+        orderedGroups.remove(group);
+        assert orderedGroups.size() == topNGroups - 1;
+      }
     } else {
       prevLast = null;
     }
@@ -336,9 +341,11 @@ public class FirstPassGroupingCollector<T> extends SimpleCollector {
     spareSlot = group.comparatorSlot;
     group.comparatorSlot = tmp;
 
-    // Re-add the changed group
+    // Re-add only if we removed it
     if (orderedGroups != null) {
-      orderedGroups.add(group);
+      if (!skipHeavyOps) {
+        orderedGroups.add(group);
+      }
       assert orderedGroups.size() == topNGroups;
       final CollectedSearchGroup<?> newLast = orderedGroups.last();
       // If we changed the value of the last group, or changed which group was last, then update