Hello!

Please review and sponsor the following patch:
http://cr.openjdk.java.net/~tvaleev/webrev/8153293/r1/

The patch preserves more characteristics on primitive stream
operations:
IntStream/LongStream/DoubleStream.boxed() preserves SORTED and DISTINCT
IntStream.asLongStream() preserves SORTED and DISTINCT
IntStream.asDoubleStream() and LongStream.asDoubleStream() preserves SORTED
(different longs can be converted into the same double, so DISTINCT is
not preserved here; not sure whether this is possible for ints)

Fixing the boxed() case is especially important as distinct() for
primitive streams is implemented like boxed().distinct().unbox, so the
actual distinct() operation cannot take the advantage of DISTINCT flag
(skip the operation at all) or SORTED flag (switch to more efficient
implementation).

Here's the small JMH benchmark which measures the performance boost of
quite common operation: sort the input numbers and leave only distinct
ones:
http://cr.openjdk.java.net/~tvaleev/webrev/8153293/jmh/

new Random(1).ints(size).sorted().distinct().toArray()

I've got the following results.

9ea+111:

Benchmark                        (size)  Mode  Cnt      Score      Error  Units
SortDistinctTest.sortedDistinct      10  avgt   30      0,612 ±    0,004  us/op
SortDistinctTest.sortedDistinct    1000  avgt   30     92,848 ±    1,039  us/op
SortDistinctTest.sortedDistinct  100000  avgt   30  32147,205 ± 3487,422  us/op

9ea+111 patched:

Benchmark                        (size)  Mode  Cnt     Score    Error  Units
SortDistinctTest.sortedDistinct      10  avgt   30     0,435 ±  0,001  us/op
SortDistinctTest.sortedDistinct    1000  avgt   30    40,555 ±  0,772  us/op
SortDistinctTest.sortedDistinct  100000  avgt   30  9031,651 ± 73,956  us/op

With best regards,
Tagir Valeev.

Reply via email to