Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid potential slow Set#removeAll call in HierarchicalCommunicator #13746

Merged
merged 4 commits into from
May 19, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Set#removeAll, if the size of
* newActiveKeyOrder is bigger than oldActive's size, then
* calling oldActive.removeAll(newActiveKeyOrder) would end
* up calling contains for all of newActiveKeyOrder items
* which is a slow operation on lists. The following avoids that:
*/
taefi marked this conversation as resolved.
Show resolved Hide resolved
newActiveKeyOrder.forEach(oldActive::remove);
taefi marked this conversation as resolved.
Show resolved Hide resolved
if (!oldActive.isEmpty()) {
passivatedByUpdate.put(Integer.valueOf(updateId), oldActive);
}
Expand Down