On Sat, 27 Jan 2024 21:58:05 GMT, Joshua Cao <d...@openjdk.org> wrote:

>> src/java.base/share/classes/java/util/HashMap.java line 503:
>> 
>>> 501:      */
>>> 502:     final void putMapEntries(Map<? extends K, ? extends V> m, boolean 
>>> evict) {
>>> 503:         int s = Math.max(size() + m.size(), m.size());
>> 
>> If we decide this approach is best, shouldn't we do the same for 
>> ConcurrentHashMap?
>
> Sure. Created https://bugs.openjdk.org/browse/JDK-8324798. Won't implement 
> that until this gets merged.

Circling back to "the case where many keys exist in both maps".  What are your 
thoughts on some optimized variant/refactoring of:
`int s = Math.max(m.size() - this.size(), 1);`

This would make it so we aggressively presize when know a large map is being 
added to a small or empty map.  Obviously, if both maps are large and don't 
contain the same keys this doesn't help.

Also, are we sure it is wise to actually call m.size() when we don't know the 
runtime of the size operation on the given map?  The only thing we can reason 
about is runtime of this.size().

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17544#discussion_r1475534839

Reply via email to