Fw: New candidate JEP: 485: Stream Gatherers
Viktor Klang
viktor.klang at oracle.com
Mon Oct 7 11:18:56 UTC 2024
(Moving this to core-libs-dev)
Cay,
Regarding 1, Characteristics was a part of the Gatherers-contract for a very long time, alas it didn't end up worth its cost. There's a longer discussion on the topic here: https://mail.openjdk.org/pipermail/core-libs-dev/2024-January/118138.html (and I'm sure that there were more, but that's the one which comes to mind)
Regarding 2, I did have a prototype which had a Downstream in the Combiner, but created a new dimension of complexity which made it even harder for people to move from sequential to parallelizable. The door isn't closed on it, but I remain unconvinced it's worth the surface area for performance reasons.
As a bit of a side-note, it's worth knowing that in the reference stream implementation, it is not unusual that parallel-capable stages are executed as "islands" which means that short-circuiting signals cannot travel across those islands. Since parallel-capable Gatherers can be fused to execute in the same "island" if we get to a place where "all" intermediate operations are parallel-capable Gatherers, there'd be a single end-to-end "island" and hence the ability to propagate the short-circuiting would be preserved in all modes of execution. Also worth knowing that a `gather(…)` immediately followed by a `collect(…)` can also be fused to run together.
Cheers,
√
Viktor Klang
Software Architect, Java Platform Group
Oracle
________________________________
From: jdk-dev <jdk-dev-retn at openjdk.org> on behalf of Cay Horstmann <cay.horstmann at gmail.com>
Sent: Friday, 4 October 2024 19:58
To: jdk-dev at openjdk.org <jdk-dev at openjdk.org>
Subject: Re: New candidate JEP: 485: Stream Gatherers
Hi, I have some belated questions about the design choices in this API that I could not find addressed in the JEP.
1. Why aren't characteristics used to express "greediness/short-circuiting" or "sequentialness/parallelizability"?
I understand that for the former I use ofGreedy/of, or implement Gatherers.Integrator.Greedy/Gatherers.Integrator. And for the latter, I use ofSequential/of, or, if I implement the Gatherer interface, have the combiner return defaultCombiner() or not.
But it seems a bit complex and less familiar than the characteristics mechanism that exists for spliterators, streams, and collectors.
The original design document (https://cr.openjdk.org/~vklang/Gatherers.html) used characteristics, so I wonder what motivated the change.
2. Why wasn't the combiner() designed to allow pushing of elements to the end of the first range's sink? Then distinctBy could be parallelized without buffering the elements. More generally, with some state fiddling one can then handle the elements around range splits.
As it is, I don't see how to parallelize such computations other than to buffer all elements.
I looked at the project at https://github.com/jhspetersson/packrat that implements a number of gatherers. Only one uses a combiner, to join buffers until their contents can be pushed in the finisher.
Cheers,
Cay
On 02/09/2024 19:55, Mark Reinhold wrote:
> https://openjdk.org/jeps/485
>
> Summary: Enhance the Stream API to support custom intermediate
> operations. This will allow stream pipelines to transform data in ways
> that are not easily achievable with the existing built-in intermediate
> operations.
>
> - Mark
--
Cay S. Horstmann | https://horstmann.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20241007/ff04014c/attachment-0001.htm>
More information about the core-libs-dev
mailing list