On Mon, 3 Jun 2024 18:48:48 GMT, Doug Lea <d...@openjdk.org> wrote:

> The jmh benchmark checks only the empty case, you need to also show lack of 
> impact on non-empty cases.

After removing `toArray`, I think this is covered.  Can you please confirm?

> Assuming you demonstrate this, it seems basically OK, (Deja vu previous cases 
> including hash maps). It is only a small band-aid -- programs generating lots 
> of them still have to allocate the COWAL object, so the savings are small 
> compared to not generating them at all unless needed.

The motivation for this change is an app that retains 23K instances of 
CopyOnWriteArrayList, 22K of which have zero items.  The 22K instances each 
have their own copy of an Object[0].  This change eliminates 343KB of retained 
memory and 22K objects.  I had initially modified `toArray()` for the sake of 
completeness but don't directly benefit from it, so I'm willing to drop that to 
remain within spec.

FWIW the issue arises inside `org.jboss.resteasy` so the benefit is broad, 
albeit shallow.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/19527#issuecomment-2147454256

Reply via email to