Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v5]

2024-02-16 Thread Joshua Cao
> This change mirrors what we did for ConcurrentHashMap in > https://github.com/openjdk/jdk/pull/17116. When we add all entries from one > map to anther, we should resize that map to the size of the sum of both maps. > > I used the command below to run the benchmarks. I set a high heap to reduce

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v4]

2024-02-09 Thread Volker Simonis
On Fri, 2 Feb 2024 17:38:13 GMT, Joshua Cao wrote: >> This change mirrors what we did for ConcurrentHashMap in >> https://github.com/openjdk/jdk/pull/17116. When we add all entries from one >> map to anther, we should resize that map to the size of the sum of both maps. >> >> I used the comman

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v4]

2024-02-08 Thread Stuart Marks
On Thu, 8 Feb 2024 17:01:15 GMT, Joshua Cao wrote: >> I think we should step back from benchmarks a bit and examine the various >> tradeoffs occurring here. Certainly we can speed things up by pre-resizing >> the map to be larger. However, this can result in a map that is too large >> for the

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v4]

2024-02-08 Thread Joshua Cao
On Wed, 7 Feb 2024 20:50:57 GMT, Stuart Marks wrote: >> Joshua Cao has updated the pull request incrementally with one additional >> commit since the last revision: >> >> extract msize variable > > I think we should step back from benchmarks a bit and examine the various > tradeoffs occurrin

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v4]

2024-02-07 Thread Stuart Marks
On Fri, 2 Feb 2024 17:38:13 GMT, Joshua Cao wrote: >> This change mirrors what we did for ConcurrentHashMap in >> https://github.com/openjdk/jdk/pull/17116. When we add all entries from one >> map to anther, we should resize that map to the size of the sum of both maps. >> >> I used the comman

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v4]

2024-02-02 Thread Joshua Cao
> This change mirrors what we did for ConcurrentHashMap in > https://github.com/openjdk/jdk/pull/17116. When we add all entries from one > map to anther, we should resize that map to the size of the sum of both maps. > > I used the command below to run the benchmarks. I set a high heap to reduce

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v3]

2024-02-01 Thread Joshua Cao
On Fri, 2 Feb 2024 04:51:33 GMT, jmehrens wrote: > 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); Calling `Math.max` is unnecessary here. Its ok if `s` ends up non-po

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v3]

2024-02-01 Thread jmehrens
On Sat, 27 Jan 2024 21:58:05 GMT, Joshua Cao wrote: >> src/java.base/share/classes/java/util/HashMap.java line 503: >> >>> 501: */ >>> 502: final void putMapEntries(Map m, boolean >>> evict) { >>> 503: int s = Math.max(size() + m.size(), m.size()); >> >> If we decide this appr

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v3]

2024-01-27 Thread Joshua Cao
On Sat, 27 Jan 2024 09:09:26 GMT, Ismael Juma wrote: >> Joshua Cao has updated the pull request incrementally with one additional >> commit since the last revision: >> >> Use max of both sizes and other maps size in case of overflow > > src/java.base/share/classes/java/util/HashMap.java line

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v3]

2024-01-27 Thread Ismael Juma
On Thu, 25 Jan 2024 00:29:40 GMT, Joshua Cao wrote: >> This change mirrors what we did for ConcurrentHashMap in >> https://github.com/openjdk/jdk/pull/17116. When we add all entries from one >> map to anther, we should resize that map to the size of the sum of both maps. >> >> I used the comma

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes

2024-01-24 Thread Joshua Cao
On Wed, 24 Jan 2024 23:53:34 GMT, jmehrens wrote: > For any Map/Collection you can fetch the Spliterator and use estimateSize or > getExactSizeIfKnown as both return size as a long. Based on the code, I think this will just return the original size. It would be the same as casting `(long) size

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v2]

2024-01-24 Thread Joshua Cao
On Wed, 24 Jan 2024 20:40:36 GMT, Joshua Cao wrote: >> This change mirrors what we did for ConcurrentHashMap in >> https://github.com/openjdk/jdk/pull/17116. When we add all entries from one >> map to anther, we should resize that map to the size of the sum of both maps. >> >> I used the comma

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v3]

2024-01-24 Thread Joshua Cao
> This change mirrors what we did for ConcurrentHashMap in > https://github.com/openjdk/jdk/pull/17116. When we add all entries from one > map to anther, we should resize that map to the size of the sum of both maps. > > I used the command below to run the benchmarks. I set a high heap to reduce

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes

2024-01-24 Thread jmehrens
On Wed, 24 Jan 2024 21:53:51 GMT, Hannes Greule wrote: >...then suggest we should change the Map::size() api to return a long... For any Map/Collection you can fetch the Spliterator and use estimateSize or getExactSizeIfKnown as both return size as a long. - PR Comment: https://gi

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes

2024-01-24 Thread Hannes Greule
On Wed, 24 Jan 2024 20:54:43 GMT, Joshua Cao wrote: > > The current benchmark and the change don't really cover the case where many > > keys exist in _both_ maps. Could you add a benchmark for that? > > I added a benchmark that assumes the worse case. Please see the top post. > Yes, this chang

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes

2024-01-24 Thread Joshua Cao
On Wed, 24 Jan 2024 19:55:27 GMT, Chen Liang wrote: > Then we might need some statistics on how often `putAll` replaces existing > mappings, ranging from none at all to completely. For example, > `Collectors.toMap` would never replace existing mappings, even though it > doesn't use `putAll` (i

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes

2024-01-24 Thread Joshua Cao
On Wed, 24 Jan 2024 19:06:49 GMT, Volker Simonis wrote: > The current benchmark and the change don't really cover the case where many > keys exist in _both_ maps. Could you add a benchmark for that? I added a benchmark that assumes the worse case. Please see the top post. Yes, this change is n

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes [v2]

2024-01-24 Thread Joshua Cao
> This change mirrors what we did for ConcurrentHashMap in > https://github.com/openjdk/jdk/pull/17116. When we add all entries from one > map to anther, we should resize that map to the size of the sum of both maps. > > I used the command below to run the benchmarks. I set a high heap to reduce

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes

2024-01-24 Thread Chen Liang
On Wed, 24 Jan 2024 00:26:09 GMT, Joshua Cao wrote: > This change mirrors what we did for ConcurrentHashMap in > https://github.com/openjdk/jdk/pull/17116. When we add all entries from one > map to anther, we should resize that map to the size of the sum of both maps. > > I used the command be

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes

2024-01-24 Thread Hannes Greule
On Wed, 24 Jan 2024 00:26:09 GMT, Joshua Cao wrote: > This change mirrors what we did for ConcurrentHashMap in > https://github.com/openjdk/jdk/pull/17116. When we add all entries from one > map to anther, we should resize that map to the size of the sum of both maps. > > I used the command be

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes

2024-01-24 Thread Volker Simonis
On Wed, 24 Jan 2024 00:26:09 GMT, Joshua Cao wrote: > This change mirrors what we did for ConcurrentHashMap in > https://github.com/openjdk/jdk/pull/17116. When we add all entries from one > map to anther, we should resize that map to the size of the sum of both maps. > > I used the command be

Re: RFR: 8324573: HashMap::putAll should resize to sum of both map sizes

2024-01-24 Thread Hannes Greule
On Wed, 24 Jan 2024 00:26:09 GMT, Joshua Cao wrote: > This change mirrors what we did for ConcurrentHashMap in > https://github.com/openjdk/jdk/pull/17116. When we add all entries from one > map to anther, we should resize that map to the size of the sum of both maps. > > I used the command be