On Wed, 8 Feb 2023 01:10:59 GMT, David Schlosnagle <d...@openjdk.org> wrote:

>> Claes Redestad has updated the pull request incrementally with one 
>> additional commit since the last revision:
>> 
>>   Minimize, force inline, generalize
>
> src/java.base/share/classes/java/util/Arrays.java line 3594:
> 
>> 3592:     public static int[] copyOf(int[] original, int newLength) {
>> 3593:         if (newLength == original.length) {
>> 3594:             return original.clone();
> 
> I am curious about the use of `clone` for some primitive array types 
> (`short[]`, `int[]`, `long[]`, `char[]`, `float[]`) and `copyOf` using 
> `System.arraycopy` in other types (`byte[]`, `double[]`). Do these types 
> optimize differently or hit different intrinsics depending on primitive type? 
> Is there difference in array zeroing?
> 
> From a quick [JMH 
> benchmark](https://gist.github.com/schlosna/975e26965ec822ad42034b3ea2b08676) 
> `System.arraycopy` seems slightly better.

I went back and forth on this and also saw a small win using `arraycopy`, but 
the PR ended up in an inconsistent state with some using one and some using the 
other. While this discrepancy seem like something we should treat as a bug, 
I've arranged to use `copyOf` helper consistently for now.

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

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

Reply via email to