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:29:46 UTC
(lucene) branch main 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 main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new 9ed912a6b1d Skip heavy TreeSet opts for the first group in FirstPassGroupingCollector (#15128)
9ed912a6b1d is described below
commit 9ed912a6b1d812e49dbe2ae5ea4995dee8693dfa
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 7a9f03ac5d7..98d26031709 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -209,6 +209,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 34686721515..3471c4ccabe 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