RFR: 8332842: Optimize empty CopyOnWriteArrayList allocations [v2]
jengebr
duke at openjdk.org
Tue Jun 4 20:00:57 UTC 2024
On Tue, 4 Jun 2024 19:41:15 GMT, Doug Lea <dl at openjdk.org> wrote:
>> src/java.base/share/classes/java/util/concurrent/CopyOnWriteArrayList.java line 103:
>>
>>> 101: private static final long serialVersionUID = 8673264195747942595L;
>>> 102:
>>> 103: private static final Object[] EMPTY_ELEMENTDATA = {};
>>
>> Looks like readObject() ought to also be changed to use the EMPTY_ELEMENTDATA if the length of the read array is 0? And perhaps `clone()`.
>
> Agreed. You might as well be consistent with this so that no one will need to re-address if some application does zillions of clones of empty lists.
I've updated `readObject` to match - thanks! `clone()` isn't a big win since the array is allocated elsewhere and the application doesn't use that code path, so I'll leave that alone for now.
Sorry, I crossed wires with @DougLea 's comment, will add `clone`.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/19527#discussion_r1626537384
PR Review Comment: https://git.openjdk.org/jdk/pull/19527#discussion_r1626538689
More information about the core-libs-dev
mailing list