JDK-8042355 stream with sorted() causes downstream ops not to be lazy
paul.sandoz at oracle.com
Tue May 6 11:02:42 UTC 2014
On May 6, 2014, at 11:30 AM, Florian Weimer <fweimer at redhat.com> wrote:
> On 05/05/2014 03:16 PM, Paul Sandoz wrote:
>> This is an optimization to ensure that sorted() in sequential pipelines does not aggressively push all sorted elements downstream if the pipeline is known to be short-circuiting.
> Would it be possible to use something like heap sort to avoid sorting the entire input stream if only the first few smallest items are needed?
For ordered streams the sort is required to be stable, and the sorted op does not know in advanced at most how many elements are required to be pushed downstream (although it might be possible to fix the latter by back-propagating more information upstream i am not sure it is worth it).
More information about the core-libs-dev