stream() / parallelStream() methods

Doug Lea dl at
Sat Feb 9 04:09:32 PST 2013

On 02/08/13 18:35, Kevin Bourrillion wrote:
> Doug, I am extraordinarily unmoved by this concern. :-)  Does a break-even point
> moving a few elements in either direction really matter?

People dealing with parallel library support need some attitude
adjustment about such things. On a soon-to-be-typical machine,
every cycle you waste setting up parallelism costs you say 64 cycles.
You would probably have had a different reaction if it required 64
object creations to start a parallel computation.

That said, I'm always completely supportive of forcing implementors
to work harder for the sake of better APIs, so long as the
APIs do not rule out efficient implementation. So if killing
parallelStream is really important, we'll find some way to
turn stream().parallel() into a bit-flip or somesuch.


> On Fri, Feb 8, 2013 at 3:28 PM, Brian Goetz <brian.goetz at
> <mailto:brian.goetz at>> wrote:
>     Depends how seriously you are counting.  Doug counts individual object
>     creations and virtual invocations on the way to a parallel operation,
>     because until you start forking, you're on the wrong side of Amdahl's law --
>     this is all "serial fraction" that happens before you can fork any work,
>     which pushes your breakeven threshold further out.  So getting the setup
>     path for parallel ops fast is valuable.
>     On 2/8/2013 6:25 PM, Kevin Bourrillion wrote:
>         On Fri, Feb 8, 2013 at 3:24 PM, Brian Goetz <brian.goetz at
>         <mailto:brian.goetz at>
>         <mailto:brian.goetz at <mailto:brian.goetz at>__>> wrote:
>                  (Tangentially, I would really love to drop parallelStream() and let
>                  people call stream().parallel(). But I haven't managed to scour the
>                  archives to find if that argument's already suitably played out.)
>              Direct version is more performant, in that it requires less wrapping
>              (to turn a stream into a parallel stream, you have to first create
>              the sequential stream, then transfer ownership of its state into a
>              new Stream.)
>         But really a lot of /work/ has already happened by then?
>         --
>         Kevin Bourrillion | Java Librarian | Google, Inc. |kevinb at
>         <mailto:kevinb at>
>         <mailto:kevinb at <mailto:kevinb at>>
> --
> Kevin Bourrillion | Java Librarian | Google, Inc. |kevinb at
> <mailto:kevinb at>

More information about the lambda-libs-spec-observers mailing list