Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-24 Thread Stuart Marks
On Tue, 24 Jan 2023 19:34:48 GMT, Viktor Klang wrote: >> Thanks @szegedi for catching this and @viktorklang-ora for fixing it. I like >> having comments like this in cases where we need to throw NPE for null and >> for which there's no explicit `Objects.requireNonNull`. We've had cases in >> t

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v5]

2023-01-24 Thread Stuart Marks
On Tue, 24 Jan 2023 19:43:14 GMT, Viktor Klang wrote: >> Currently Set.copyOf allocates both a HashSet and a new empty array when the >> input collection is empty. >> >> This patch avoids allocating anything for the case where the parameter >> collection's isEmpty returns true. > > Viktor Klan

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-24 Thread Viktor Klang
On Tue, 24 Jan 2023 18:00:30 GMT, Stuart Marks wrote: >> src/java.base/share/classes/java/util/ImmutableCollections.java line 174: >> >>> 172: return List.of(); >>> 173: } else { >>> 174: return (List)List.of(coll.toArray()); // implicit >>> nullcheck of coll >>

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v5]

2023-01-24 Thread Roger Riggs
On Tue, 24 Jan 2023 19:38:58 GMT, Viktor Klang wrote: >> Currently Set.copyOf allocates both a HashSet and a new empty array when the >> input collection is empty. >> >> This patch avoids allocating anything for the case where the parameter >> collection's isEmpty returns true. > > Viktor Klan

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v5]

2023-01-24 Thread Viktor Klang
> Currently Set.copyOf allocates both a HashSet and a new empty array when the > input collection is empty. > > This patch avoids allocating anything for the case where the parameter > collection's isEmpty returns true. Viktor Klang has updated the pull request incrementally with one additional

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-24 Thread Stuart Marks
On Sun, 22 Jan 2023 15:20:18 GMT, Attila Szegedi wrote: >> Viktor Klang has updated the pull request incrementally with two additional >> commits since the last revision: >> >> - 8299444: java.util.Set.copyOf allocates needlessly for empty input >> collections >> >>Modifies Immuta

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-24 Thread Rémi Forax
On Tue, 24 Jan 2023 13:40:37 GMT, Viktor Klang wrote: >> `coll instanceof ListN list` should work. > > @forax @stuart-marks Yeah, that works. It's unfortunate that it's not > possible to match on the actual (generic) type, as then both sides of the || > could use type unification to avoid havin

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-24 Thread Viktor Klang
On Tue, 24 Jan 2023 11:07:07 GMT, Rémi Forax wrote: >> @stuart-marks Sorry, missed this notification. I initially had the same >> idea, but decided against it because it forces me to suppress "rawtypes" >> since `coll instanceof ListN` is not considered to be a rawtype, but `coll >> instanceof

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v4]

2023-01-24 Thread Viktor Klang
> Currently Set.copyOf allocates both a HashSet and a new empty array when the > input collection is empty. > > This patch avoids allocating anything for the case where the parameter > collection's isEmpty returns true. Viktor Klang has updated the pull request incrementally with one additional

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-24 Thread Rémi Forax
On Tue, 24 Jan 2023 10:23:14 GMT, Viktor Klang wrote: >> src/java.base/share/classes/java/util/ImmutableCollections.java line 169: >> >>> 167: @SuppressWarnings("unchecked") >>> 168: static List listCopy(Collection coll) { >>> 169: if (coll instanceof List12 || (coll instanceof

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-24 Thread Viktor Klang
On Sun, 22 Jan 2023 15:20:18 GMT, Attila Szegedi wrote: >> Viktor Klang has updated the pull request incrementally with two additional >> commits since the last revision: >> >> - 8299444: java.util.Set.copyOf allocates needlessly for empty input >> collections >> >>Modifies Immuta

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-24 Thread Viktor Klang
On Mon, 9 Jan 2023 18:26:56 GMT, Stuart Marks wrote: >> Viktor Klang has updated the pull request incrementally with two additional >> commits since the last revision: >> >> - 8299444: java.util.Set.copyOf allocates needlessly for empty input >> collections >> >>Modifies Immutable

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v3]

2023-01-24 Thread Viktor Klang
> Currently Set.copyOf allocates both a HashSet and a new empty array when the > input collection is empty. > > This patch avoids allocating anything for the case where the parameter > collection's isEmpty returns true. Viktor Klang has updated the pull request incrementally with one additional

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-22 Thread Attila Szegedi
On Mon, 9 Jan 2023 08:33:09 GMT, Viktor Klang wrote: >> Currently Set.copyOf allocates both a HashSet and a new empty array when the >> input collection is empty. >> >> This patch avoids allocating anything for the case where the parameter >> collection's isEmpty returns true. > > Viktor Klang

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-10 Thread Per Minborg
On Mon, 9 Jan 2023 18:34:57 GMT, Per Minborg wrote: > On the note of `CHM::isEmpty`: It would be better to rewrite this method as a > short-circuitable reduction of the many CounterCells' values. As soon as at > least one of them are >0 then the map is not empty. In contrast, today we sum > al

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-09 Thread Viktor Klang
On Mon, 9 Jan 2023 18:34:57 GMT, Per Minborg wrote: >> Viktor Klang has updated the pull request incrementally with two additional >> commits since the last revision: >> >> - 8299444: java.util.Set.copyOf allocates needlessly for empty input >> collections >> >>Modifies ImmutableC

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-09 Thread Per Minborg
On Mon, 9 Jan 2023 08:33:09 GMT, Viktor Klang wrote: >> Currently Set.copyOf allocates both a HashSet and a new empty array when the >> input collection is empty. >> >> This patch avoids allocating anything for the case where the parameter >> collection's isEmpty returns true. > > Viktor Klang

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-09 Thread Stuart Marks
On Mon, 9 Jan 2023 08:33:09 GMT, Viktor Klang wrote: >> Currently Set.copyOf allocates both a HashSet and a new empty array when the >> input collection is empty. >> >> This patch avoids allocating anything for the case where the parameter >> collection's isEmpty returns true. > > Viktor Klang

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-09 Thread Stuart Marks
On Mon, 9 Jan 2023 08:33:09 GMT, Viktor Klang wrote: >> Currently Set.copyOf allocates both a HashSet and a new empty array when the >> input collection is empty. >> >> This patch avoids allocating anything for the case where the parameter >> collection's isEmpty returns true. > > Viktor Klang

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-09 Thread Viktor Klang
On Mon, 9 Jan 2023 17:09:02 GMT, Sergey Bylokhov wrote: >> Viktor Klang has updated the pull request incrementally with two additional >> commits since the last revision: >> >> - 8299444: java.util.Set.copyOf allocates needlessly for empty input >> collections >> >>Modifies Immuta

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-09 Thread Sergey Bylokhov
On Mon, 9 Jan 2023 08:33:09 GMT, Viktor Klang wrote: >> Currently Set.copyOf allocates both a HashSet and a new empty array when the >> input collection is empty. >> >> This patch avoids allocating anything for the case where the parameter >> collection's isEmpty returns true. > > Viktor Klang

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections

2023-01-09 Thread Viktor Klang
On Thu, 5 Jan 2023 01:02:11 GMT, Sergey Bylokhov wrote: >> There's no regression test. However, with the current code (prior to this >> change) a call to `Set.of(zeroLengthArray)` returns the same instance as >> `Set.of()`, so it's difficult to write a simple functional test for this >> change

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections [v2]

2023-01-09 Thread Viktor Klang
> Currently Set.copyOf allocates both a HashSet and a new empty array when the > input collection is empty. > > This patch avoids allocating anything for the case where the parameter > collection's isEmpty returns true. Viktor Klang has updated the pull request incrementally with two additional

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections

2023-01-05 Thread Viktor Klang
On Thu, 5 Jan 2023 01:02:11 GMT, Sergey Bylokhov wrote: >> There's no regression test. However, with the current code (prior to this >> change) a call to `Set.of(zeroLengthArray)` returns the same instance as >> `Set.of()`, so it's difficult to write a simple functional test for this >> change

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections

2023-01-04 Thread Sergey Bylokhov
On Wed, 4 Jan 2023 19:39:23 GMT, Stuart Marks wrote: > so it's difficult to write a simple functional test for this change. It is possible to track that for some "custom" and empty collection the only method will be called is `isEmpty` and nothing else. Not sure how it is useful or not. -

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections

2023-01-04 Thread Stuart Marks
On Wed, 4 Jan 2023 14:41:20 GMT, Viktor Klang wrote: > Currently Set.copyOf allocates both a HashSet and a new empty array when the > input collection is empty. > > This patch avoids allocating anything for the case where the parameter > collection's isEmpty returns true. There's no regressio

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections

2023-01-04 Thread Aleksey Shipilev
On Wed, 4 Jan 2023 14:41:20 GMT, Viktor Klang wrote: > Currently Set.copyOf allocates both a HashSet and a new empty array when the > input collection is empty. > > This patch avoids allocating anything for the case where the parameter > collection's isEmpty returns true. Looks okay. This rel

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections

2023-01-04 Thread Viktor Klang
On Wed, 4 Jan 2023 15:20:10 GMT, Pavel Rappo wrote: >> Currently Set.copyOf allocates both a HashSet and a new empty array when the >> input collection is empty. >> >> This patch avoids allocating anything for the case where the parameter >> collection's isEmpty returns true. > > Curious: how

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections

2023-01-04 Thread Pavel Rappo
On Wed, 4 Jan 2023 14:41:20 GMT, Viktor Klang wrote: > Currently Set.copyOf allocates both a HashSet and a new empty array when the > input collection is empty. > > This patch avoids allocating anything for the case where the parameter > collection's isEmpty returns true. Curious: how bad was

Re: RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections

2023-01-04 Thread Roger Riggs
On Wed, 4 Jan 2023 14:41:20 GMT, Viktor Klang wrote: > Currently Set.copyOf allocates both a HashSet and a new empty array when the > input collection is empty. > > This patch avoids allocating anything for the case where the parameter > collection's isEmpty returns true. LGTM -

RFR: 8299444 java.util.Set.copyOf allocates needlessly for empty input collections

2023-01-04 Thread Viktor Klang
Currently Set.copyOf allocates both a HashSet and a new empty array when the input collection is empty. This patch avoids allocating anything for the case where the parameter collection's isEmpty returns true. - Commit messages: - 8299444: java.util.Set.copyOf allocates needlessly