Skip to content

Commit

Permalink
fix: Avoid potential slow Set#removeAll call in HierarchicalCommunica…
Browse files Browse the repository at this point in the history
…tor (#13746)

* fix: Avoid potential slow Set#removeAll call in HierarchicalCommunicationController#passivateInactiveKeys

The performance of calling Set#removeAll(List) is dependent on the relative sizes of the Set and List parameter. Replace Set#removeAll with List#forEach(Set::remove) to avoid this.

Fixes #13745

Co-authored-by: Mikhail Shabarov <[email protected]>
Co-authored-by: Soroosh Taefi <[email protected]>
  • Loading branch information
3 people authored and vaadin-bot committed May 19, 2022
1 parent c3101ad commit 9ca456d
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,14 @@ private void passivateInactiveKeys(Set<String> oldActive,
}

// Finally clear any passivated items that have now been confirmed
oldActive.removeAll(newActiveKeyOrder);
/*
* Due to the implementation of AbstractSet#removeAll, if the size
* of newActiveKeyOrder is bigger than oldActive's size, then
* calling oldActive.removeAll(newActiveKeyOrder) would end up
* calling contains method for all of newActiveKeyOrder items which
* is a slow operation on lists. The following avoids that:
*/
newActiveKeyOrder.forEach(oldActive::remove);
if (!oldActive.isEmpty()) {
passivatedByUpdate.put(Integer.valueOf(updateId), oldActive);
}
Expand Down

0 comments on commit 9ca456d

Please sign in to comment.