On Wed, 4 Jan 2023 15:20:10 GMT, Pavel Rappo <pra...@openjdk.org> 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 that "needless allocation" that it was required to be 
> optimized away?

@pavelrappo Fair question! I guess it depends on what dominates the benchmark: 
given that the copyOf methods goes to some length to try to avoid allocating 
new instances of the immutable sets the proposed patch seemed like rather 
low-hanging fruit. I found this as I was running some (to be fair, rather 
specific) benches which drew my attention to it.

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

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

Reply via email to