RFR: 8215995: Add specialized toArray methods to immutable collections

Martin Buchholz martinrb at google.com
Wed Jan 2 19:00:35 UTC 2019


Looks good to me.

Can you explain why there are two identical test methods get and get2 ?

I was surprised by the use of SALT in SetN. I'm guessing you could improve
SetN by adapting the tricky circular array traversal code from ArrayDeque.
I'm not convinced that the extra non-determinism from negative SALT pulls
its weight.

On Wed, Jan 2, 2019 at 10:12 AM Claes Redestad <claes.redestad at oracle.com>
wrote:

> Hi,
>
> the Set and List implementations in java.util.ImmutableCollections
> inherits toArray from AbstractCollection, whose implementations always
> fall back to an iterator-based approach. Additionally there's logic to
> deal with not getting the expected number of elements from the iterator,
> which can't happen for these immutable collections.
>
> This patch add specialized implementations, along with a microbenchmark
> to back up the claim that these are actually faster (a few tests I
> created when working on JDK-8193128 are also included).
>
> Webrev: http://cr.openjdk.java.net/~redestad/8215995/jdk.00/
> Bug:    https://bugs.openjdk.java.net/browse/JDK-8215995
>
> Test running:
> java -jar build/linux-x64/images/test/micro/benchmarks.jar Immutable.*to
> -f 5 -w 4 -r 4:
>
> Baseline:
> Benchmark                             Mode  Cnt  Score   Error   Units
> ImmutableColls.toArrayFromList       thrpt   25  2.949 ± 0.031  ops/us
> ImmutableColls.toArrayFromSet        thrpt   25  3.822 ± 0.075  ops/us
> ImmutableColls.toTypedArrayFromList  thrpt   25  2.474 ± 0.023  ops/us
> ImmutableColls.toTypedArrayFromSet   thrpt   25  3.237 ± 0.085  ops/us
>
> Patch:
> Benchmark                             Mode  Cnt  Score   Error   Units
> ImmutableColls.toArrayFromList       thrpt   25  7.939 ± 0.101  ops/us
> ImmutableColls.toArrayFromSet        thrpt   25  5.399 ± 0.099  ops/us
> ImmutableColls.toTypedArrayFromList  thrpt   25  3.941 ± 0.003  ops/us
> ImmutableColls.toTypedArrayFromSet   thrpt   25  4.111 ± 0.101  ops/us
>
> These micros use a mix of Set12/SetN and List12/ListN/SubList -
> larger speedups could be provoked if only testing 1 and 2-elements lists
> and sets, but I don't want to be too synthetic.
>
> Thanks!
>
> /Claes
>


More information about the core-libs-dev mailing list