I'm implementing a Spliterator
that explicitly restricts parallelization by having trySplit()
return null
. Would implementing estimateSize()
offer any performance improvements for a stream produced by this spliterator? Or is the estimated size only useful for parallelization?
EDIT: To clarify, I'm specifically asking about an estimated size. In other words, my spliterator does not have the SIZED
characteristic.
Like Iterator and ListIterator, Spliterator is a Java Iterator, which is used to iterate elements one-by-one from a List implemented object. Some important points about Java Spliterator are: Java Spliterator is an interface in Java Collection API. Spliterator is introduced in Java 8 release in java.
stream(spliterator(), false); } default Stream<E> parallelStream() { return StreamSupport. stream(spliterator(), true); } ... Spliterator is an internal iterator that breaks the stream into the smaller parts. These smaller parts can be processed in parallel.
Looking at the call hierarchy to the relevant spliterator characteristic reveals that it's at least relevant for stream.toArray()
performance
Additionally there is an equivalent flag in the internal stream implementation that seems to be used for sorting:
So aside from parallel stream operations the size estimate seems to be used for those two operations.
I don't claim exhaustiveness for my search, so just take these as examples.
Without the SIZED characteristic I can only find calls to estimateSize()
that are relevant to parallel execution of the stream pipeline.
Of course this might change in the future or another Stream implementation than the standard JDK one could act differently.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With