RFR: 8193031: Collections.addAll is likely to perform worse than Collection.addAll
Сергей Цыпанов
github.com+10835776+stsypanov at openjdk.java.net
Mon Dec 21 14:30:02 UTC 2020
On Mon, 21 Dec 2020 11:32:28 GMT, Pavel Rappo <prappo at openjdk.org> wrote:
>> Hi all,
>>
>> According to the document of [SafeVarargs](https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/SafeVarargs.html).
>>
>>> Compilers are encouraged to issue warnings when this annotation type is applied to a method or constructor declaration where:
>>
>>> The body of the method or constructor declaration performs potentially unsafe operations, such as an assignment to an element of the variable arity parameter's array that generates an unchecked warning.
>>
>> The `SafeVarargs` may not suppress the warning of this assignment and the `SuppressWarnings` may be necessary.
>>
>> If you still think it is the bug of compiler. I suggest that you move the bug discussion to the compiler-dev at openjdk.java.net to solve the bug as soon as possible.
>
> This message is purely informational: I may have found a JBS comment that provides historical context for that "this method is likely to run significantly faster under most implementations" phrase. Here: https://bugs.openjdk.java.net/browse/JDK-4822887?focusedCommentId=12241154&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-12241154
@pavelrappo the problem is that people still believe this message and use this utility method widely: see e.g. https://github.com/spring-projects/spring-framework/pull/23478
They expect it to improve performance, but in fact it degradates. Also for some cases it degrade dramatically, e.g. when instead of `ArrayList` `COWArrayList` comes as argument
@pavelrappo also see this not very old comment: https://github.com/spring-projects/spring-framework/pull/24636#pullrequestreview-370684078
-------------
PR: https://git.openjdk.java.net/jdk/pull/1764
More information about the core-libs-dev
mailing list