JDK-8042355 stream with sorted() causes downstream ops not to be lazy
Hi, https://bugs.openjdk.java.net/browse/JDK-8042355 http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8042355-sorted-short-circuit/we... 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. Note that it is not an error that more elements, than strictly required to produce a result, may flow through the pipeline. This can occur, in general (not restricted to just sorting), for short-circuiting parallel pipelines. Paul.
Looks good to me. On May 5 2014, at 06:16 , Paul Sandoz <paul.sandoz@oracle.com> wrote:
Hi,
https://bugs.openjdk.java.net/browse/JDK-8042355 http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8042355-sorted-short-circuit/we...
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.
Note that it is not an error that more elements, than strictly required to produce a result, may flow through the pipeline. This can occur, in general (not restricted to just sorting), for short-circuiting parallel pipelines.
Paul.
On 05/05/2014 03:16 PM, Paul Sandoz wrote:
Hi,
https://bugs.openjdk.java.net/browse/JDK-8042355 http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8042355-sorted-short-circuit/we...
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? -- Florian Weimer / Red Hat Product Security Team
On May 6, 2014, at 11:30 AM, Florian Weimer <fweimer@redhat.com> wrote:
On 05/05/2014 03:16 PM, Paul Sandoz wrote:
Hi,
https://bugs.openjdk.java.net/browse/JDK-8042355 http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8042355-sorted-short-circuit/we...
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). Paul.
This is an optimization that is theoretically possible (and was anticipated in the design), but in reality is likely to be so low-priority that it would be a really long time before it was worth putting engineering resources on this. It would have to be an unordered stream, and we'd have to know that the downstream pipeline is short-circuiting. (There is some back-propagation of characteristics for situations like this, but we have to be careful not to tax startup of common pipelines like filter-map-reduce just to support weird pipelines like this.) On 5/6/2014 5:30 AM, Florian Weimer wrote:
On 05/05/2014 03:16 PM, Paul Sandoz wrote:
Hi,
https://bugs.openjdk.java.net/browse/JDK-8042355
http://cr.openjdk.java.net/~psandoz/jdk9/JDK-8042355-sorted-short-circuit/we...
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?
participants (4)
-
Brian Goetz
-
Florian Weimer
-
Mike Duigou
-
Paul Sandoz