Change `set.removeAll(list)` to `list.forEach(set::remove)` (#13052)

This commit is contained in:
Dmitry Cherniachenko 2024-01-30 11:39:15 +01:00 committed by GitHub
parent d988f91aba
commit 39c10a2929
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -228,6 +228,8 @@ Optimizations
this will help boolean queries that consist of a mix OF FILTER clauses and
SHOULD clauses. (Adrien Grand)
* GITHUB#13052: Avoid set.removeAll(list) O(n^2) performance trap in the UpgradeIndexMergePolicy (Dmitry Cherniachenko)
Bug Fixes
---------------------
* GITHUB#12866: Prevent extra similarity computation for single-level HNSW graphs. (Kaival Parikh)

View File

@ -106,7 +106,11 @@ public class UpgradeIndexMergePolicy extends FilterMergePolicy {
// the resulting set contains all segments that are left over
// and will be merged to one additional segment:
for (final OneMerge om : spec.merges) {
oldSegments.keySet().removeAll(om.segments);
// om.segments.forEach(::remove) is used here instead of oldSegments.keySet().removeAll()
// for performance reasons; when om.segments.size() == oldSegments.size()
// the AbstractSet#removeAll() implementation will iterate the set elements
// calling list.contains() for each of them, resulting in O(n^2) performance
om.segments.forEach(oldSegments::remove);
}
}