Hi Rémi,

You can find some of my benches here: 
https://github.com/openjdk/jdk/tree/master/test/micro/org/openjdk/bench/java/util/stream/ops/ref

Initially I had Characteristics such as ORDERED etc on Gatherer but it just 
didn't end up worth it when looking at the bench results over a wide array of 
stream sizes and number of operations.

Cheers,
√


Viktor Klang
Software Architect, Java Platform Group
Oracle
________________________________
From: core-libs-dev <core-libs-dev-r...@openjdk.org> on behalf of Remi Forax 
<fo...@univ-mlv.fr>
Sent: Wednesday, 17 January 2024 16:48
To: core-libs-dev <core-libs-...@openjdk.java.net>
Subject: Gatherer: spliterator characteristics are not propagated

While doing some benchmarking of the Gatherer API, i've found that the 
characteristics of the spliterator was not propagated by the method 
Stream.gather() making the stream slower than it should.

As an example, there is no way when reimplementing map() using a Gatherer to 
say that this intermediate operation keep the size, which is important if the 
terminal operation is toList() because if the size is known, toList() will 
presize the List and avoid the creation of an intermediary ArrayList.

See 
https://github.com/forax/we_are_all_to_gather/blob/master/src/main/java/com/gihtub/forax/wearealltogather/bench/MapGathererBenchmark.java

I think that adding a way to propagate the spliterator characteristics through 
a Gatherer would greatly improve the performance of commons streams (at least 
all the ones that end with a call to toList).

I have some idea of how to do that, but I prefer first to hear if i've overlook 
something and if improving the performance is something worth changing the API.

regards,
Rémi

Reply via email to