CopyOnWriteArrayList Collection.shuffle

Zelva Lia jolyjdia at gmail.com
Fri Aug 19 10:49:54 UTC 2022


Hello, when shuffling the CopyOnWrite list with the standard
Collections.shuffle method, performance anomalies occur, due to the fact
that it calls the set method, which copies the array each time, a possible
solution (crutch) is a random comparator for sorting, so sorting in COW is
redefined to its own sub - blocking implementation

Another problem with Collections.shuffle is that it's not exactly thread
safe because it calls the size() method; and then iterates from it, also
COW does not support modification inside the iterator (works on snapshots)


COWCollectionsShuffle      0,008 ops/ms
COWListRandomSort         1,089 ops/ms
syncListCollectionsShuffle  0,950 ops/ms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20220819/cc786ff4/attachment.htm>


More information about the core-libs-dev mailing list