RFR: 8371656: HashMap.putAll() optimizations [v3]

jengebr duke at openjdk.org
Wed Feb 11 19:27:37 UTC 2026


On Wed, 11 Feb 2026 18:57:02 GMT, Rémi Forax <forax at openjdk.org> wrote:

>> What issue?  This is an integral part of the performance optimization.
>
> Your PR proposes two optimizations,
> - HashMap.putAll(HashMap) 
> - HashMap.putAll(UnmodifiableMap(HashMap))
>  
> The former have been done numerous time for other collections, the latter is as far as as know new.
> 
> There are several reasons to not wanting to do the latter , on top of my head:
> - this is not a symmetrical transformation,
> - why only have this optimization on HashMap and not ArrayList and/or ArrayDeque ? 
> 
> So It's a separate issue that should be discussed on on the mailist list first.

Hmm, I disagree, since they are both aspects of improving performance of the target method, HashMap.putMapEntries().  They also both directly attack the underlying JDK JIT limitations described in https://bugs.openjdk.org/browse/JDK-8368292 .  It's a two-piece fix to one problem, and they're covered simultaneously by a single unit test and JMH benchmark.

Open to opinions from others.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/28243#discussion_r2795064430


More information about the core-libs-dev mailing list