Re: [10] RFR 8193856 takeWhile produces incorrect result with elements produced by flatMap

2017-12-20 Thread Stuart Marks



On 12/20/17 1:28 PM, Paul Sandoz wrote:

Please review this fix for a bug in the stream takeWhile operation:

   
http://cr.openjdk.java.net/~psandoz/jdk10/JDK-8193856-takeWhile-incorrect-results/webrev/
 


The flatMap operation is currently aggressive and does not detect if a 
downstream operation may or has cancelled processing, and will push all of it’s 
elements downstream. Short-circuiting operations should be guarded against such 
behaviour but unfortunately takeWhile was not guarded.


Hi Paul,

Change looks fine. Good to get this one into JDK 10.

Thanks,

s'marks



Re: [10] RFR 8193856 takeWhile produces incorrect result with elements produced by flatMap

2017-12-20 Thread Paul Sandoz

Hi Jonathan,

> On 20 Dec 2017, at 14:47, Jonathan Bluett-Duncan  
> wrote:
> 
> Hi Paul,
> 
> It seems that some clever Googler managed to find a workaround for aggressive 
> `flatMap` operations in the form of a so-called `MoreStreams.flatten` 
> operation, implemented in a side project called google/mug.

Thanks. MoreStreams.flatten “lowers” a stream of streams to a spliterator of 
spliterators which in turn is input as a new stream source, enabling a 
cancellation check + tryAdvance for any following short-circuit or terminal ops.

I have a solution in the works for flatMap based on sorted operation (which has 
to buffer all elements, sort ‘em, then push ‘em all downstream).

Paul.

> I'm sharing the javadoc 
> 
>  and GitHub project homepage  with you and the 
> rest of the mailing list in the hope that they prove to be useful.
> 
> Cheers,
> Jonathan
> 
> On 20 December 2017 at 21:28, Paul Sandoz  > wrote:
> Hi,
> 
> Please review this fix for a bug in the stream takeWhile operation:
> 
>   
> http://cr.openjdk.java.net/~psandoz/jdk10/JDK-8193856-takeWhile-incorrect-results/webrev/
>  
> 
>  
>   
> >
> 
> The flatMap operation is currently aggressive and does not detect if a 
> downstream operation may or has cancelled processing, and will push all of 
> it’s elements downstream. Short-circuiting operations should be guarded 
> against such behaviour but unfortunately takeWhile was not guarded.
> 
> —
> 
> Separately i plan to figure out a way to ensure flatMap operations become 
> less aggressive if there are short-circuiting downstream operations. This may 
> increase efficiency and also allow support for flat map results that are 
> infinite.
> 
> Paul.
> 



Re: [10] RFR 8193856 takeWhile produces incorrect result with elements produced by flatMap

2017-12-20 Thread Jonathan Bluett-Duncan
Hi Paul,

It seems that some clever Googler managed to find a workaround for
aggressive `flatMap` operations in the form of a so-called
`MoreStreams.flatten` operation, implemented in a side project called
google/mug. I'm sharing the javadoc

and
GitHub project homepage  with you and the
rest of the mailing list in the hope that they prove to be useful.

Cheers,
Jonathan

On 20 December 2017 at 21:28, Paul Sandoz  wrote:

> Hi,
>
> Please review this fix for a bug in the stream takeWhile operation:
>
>   http://cr.openjdk.java.net/~psandoz/jdk10/JDK-8193856-
> takeWhile-incorrect-results/webrev/  psandoz/jdk10/JDK-8193856-takeWhile-incorrect-results/webrev/>
>
> The flatMap operation is currently aggressive and does not detect if a
> downstream operation may or has cancelled processing, and will push all of
> it’s elements downstream. Short-circuiting operations should be guarded
> against such behaviour but unfortunately takeWhile was not guarded.
>
> —
>
> Separately i plan to figure out a way to ensure flatMap operations become
> less aggressive if there are short-circuiting downstream operations. This
> may increase efficiency and also allow support for flat map results that
> are infinite.
>
> Paul.
>


[10] RFR 8193856 takeWhile produces incorrect result with elements produced by flatMap

2017-12-20 Thread Paul Sandoz
Hi,

Please review this fix for a bug in the stream takeWhile operation:

  
http://cr.openjdk.java.net/~psandoz/jdk10/JDK-8193856-takeWhile-incorrect-results/webrev/
 


The flatMap operation is currently aggressive and does not detect if a 
downstream operation may or has cancelled processing, and will push all of it’s 
elements downstream. Short-circuiting operations should be guarded against such 
behaviour but unfortunately takeWhile was not guarded.

—

Separately i plan to figure out a way to ensure flatMap operations become less 
aggressive if there are short-circuiting downstream operations. This may 
increase efficiency and also allow support for flat map results that are 
infinite.

Paul.