On Mon, 30 Mar 2026 17:43:33 GMT, jengebr <[email protected]> wrote:

>> 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.

On second thought, this optimization is ok, but we should still document inline 
the purpose of this is to allow better type profiling of the underlying 
collection.

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

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

Reply via email to