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

Viktor Klang duke at openjdk.org
Mon Jan 9 17:34:55 UTC 2023


On Mon, 9 Jan 2023 17:09:02 GMT, Sergey Bylokhov <serb at openjdk.org> 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 ImmutableCollections.listCopy:
>>        Introduces a check for isEmpty to avoid allocation in the case of an empty input collection.
>>  - 8299444: java.util.Set.copyOf allocates needlessly for empty input collections
>>    
>>    Modifies Map.copyOf:
>>    Introduces a check for isEmpty to avoid allocation in the case of an empty input Map.
>
> I wonder how it will affect (if any) the performance of the common path, for example if non-empty but small ConcurrentHashMap is passed to the List.copyOf().

@mrserb The "hit" is directly proportional to the cost of `isEmpty()`—but specifically for collections like ConcurrentHashMap, the very notion of "current size" is challenging at best.

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

PR: https://git.openjdk.org/jdk/pull/11847


More information about the core-libs-dev mailing list