RFR: 8196340: (coll) Examine overriding inherited methods in ArrayList and ArrayList.SubList

Claes Redestad claes.redestad at oracle.com
Fri May 11 21:52:06 UTC 2018


Right, and with the patch I've proposed ArrayList#hashCode is on par 
with current COWAL on my machine in your micro:

$ ~/src/jdk/build/linux-x64/images/jdk/bin/java -cp 
./open/test/jdk/java/util/Collection IteratorMicroBenchmark 
filter=ArrayList.*hashCode.*
Method                        Millis Ratio
ArrayList hashCode                34 1.000
ArrayList$SubList hashCode        34 1.009
CopyOnWriteArrayList hashCode     34 0.999

I'm about to start testing of an updated patch, will send a new webrev 
if and when things look green.

Thanks!

/Claes

On 2018-05-11 21:53, Martin Buchholz wrote:
> Yet another way to iterate over a collection.  Coming in via jsr166 soon.
>
> Seeing CopyOnWriteArrayList beat ArrayList decisively suggests that 
> optimizing it is defintely worth doing.
>
> And of course the numbers below contain more low-hanging fruit if 
> anyone still cares about the performance of LinkedList or Vector.
>
> Have you considered adding public ranged methods on Arrays?  We 
> currently only have the "deranged" Arrays.hashCode(Object[])
>
> --- IteratorMicroBenchmark.java9 May 2018 17:43:01 -00001.44
> +++ IteratorMicroBenchmark.java11 May 2018 18:18:37 -0000
> @@ -34,6 +34,7 @@
>  import java.lang.ref.ReferenceQueue;
>  import java.lang.ref.WeakReference;
>  import java.util.ArrayDeque;
> +import java.util.Arrays;
>  import java.util.ArrayList;
>  import java.util.Collection;
>  import java.util.Collections;
> @@ -562,6 +563,12 @@
>                      for (int i = 0; i < iterations; i++) {
>  sum[0] = 0;
>  x.replaceAll(sneakyAdder);
> - check.sum(sum[0]);}}});
> + check.sum(sum[0]);}}},
> +            new Job(klazz + " hashCode") {
> +                public void work() throws Throwable {
> +                    int hashCode = Arrays.hashCode(x.toArray());
> +                    for (int i = 0; i < iterations; i++) {
> + if (x.hashCode() != hashCode)
> +     throw new AssertionError();}}});
>      }
>  }
>
>
> C2:
> Method               Millis Ratio
> ArrayList hashCode                   94 1.000
> ArrayList$SubList hashCode                97 1.031
> LinkedList hashCode                    92 0.974
> AbstractList$SubList hashCode            111 1.172
> Vector hashCode                    82 0.866
> SynchronizedRandomAccessList hashCode     97 1.022
> CopyOnWriteArrayList hashCode              8 0.091
> COWSubList hashCode                     8 0.090
>
> C1:
> Method               Millis Ratio
> ArrayList hashCode                  112 1.000
> ArrayList$SubList hashCode               118 1.060
> LinkedList hashCode                   118 1.054
> AbstractList$SubList hashCode            276 2.472
> Vector hashCode                   126 1.132
> SynchronizedRandomAccessList hashCode    293 2.620
> CopyOnWriteArrayList hashCode             37 0.330
> COWSubList hashCode                    36 0.325
>



More information about the core-libs-dev mailing list