Optimize WeakConcurrentCollection removeAll and retainAll lookup complexity - #329
Optimize WeakConcurrentCollection removeAll and retainAll lookup complexity#329Smorki wants to merge 5 commits into
Conversation
|
Why did you remove Objects/NonNull imports while retaining their uses? Does not compile. |
|
oh iy was accidentally removed during the web conflict resolution. Just pushed a fix to restore the missing imports |
…thub.com/Smorki/Canvas into perf/optimize-weak-concurrent-collection
|
🥀 |
|
Even after the compile issue is fixed, I don't think this is a good idea as written. |
|
Fair points, especially regarding the behavioral difference with identity-based collections and the lack of current call sites within Canvas I see now that adding this complexity might be premature without a concrete use case or benchmark. |
In
WeakConcurrentCollection#removeAlland#retainAll, callingc.contains(value)inside the loop gets slow whencis a List.This PR wraps
cinto aHashSetprior to iteration if it's not already aSetto make lookups O(1). It also handles empty collections cleanly to stay compliant with standard Java Collection behavior.