On Mon, 30 Mar 2026 16:34:44 GMT, Chen Liang <[email protected]> wrote:

>> 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.
>
> I do agree with Remi that the UnmodifiableMap special path provides little 
> value. The unmodifiable map itself is megamorphic and its own iteration would 
> suffer from the same profiling issue if we eliminate the "bottleneck" here.

Actually, one of the most common patterns in our application code is that a 
library returns an UnmodifiableMap wrapping a HashMap.  Unwrapping that 
UnmodifiableMap here 1) eliminates a megamorphic loop across 
Unmodifiable.entrySet(), 2) enables the further optimization via the HashMap 
fastpath.  As noted in the benchmarks, the benefit to this case is a 3.5x 
increase in throughput.

I can see an argument that this isn't a frequent enough case (my data 
notwithstanding), but when this case comes up, it is indeed valuable.

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

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

Reply via email to