<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Cay,</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
>Maybe just a mental block on my side. If other programmers worked with the API and found it consistent, don't mind me. I just thought to bring it up in case this has not received a lot of scrutiny. It is a pretty specialized aspect, after all.</div>
<div id="Signature" class="" style="color: inherit;">
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Perhaps the best thing here is to just let it sit for a while and see if some time is all that's needed.<br>
<br>
>PS. I also think it would be helpful to be more explicit in the javadoc about the value of exploiting greediness. What is the sweet spot? Recognizing that nothing in the pipeline is short-circuiting and then pushing elements through without checking? Or more
 aggressive parallelization?</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I guess it depends on "sweet spot from whom". From an implementor perspective if you don't intend to initiate a short-circuit signal, using ofGreedy is a good way to both remind yourself, and send that signal to Gatherer-evaluators. Omitting ofGreedy won't
 break anything. If you implement a Gatherer-evaluator, I think it is safe to presume that it completely depends on the use-case¡Xand of course all optimization work should be based on sensible benchmarking.<br>
<br>
>I looked at the source code of Gatherer/Gatherers/GathererOp, and it is not obvious to me how one can see a significant performance win with greediness. Can you recommend a benchmark for me to study?</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
I think it makes sense to look at the mentions of "greedy" in GathererOp and Gatherers (specifically the composition).<br>
<br>
</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
There are a fair number of benchmarks here (they all start with "Gather"): <a href="https://github.com/openjdk/jdk/tree/master/test/micro/org/openjdk/bench/java/util/stream/ops/ref" id="LPlnk">
https://github.com/openjdk/jdk/tree/master/test/micro/org/openjdk/bench/java/util/stream/ops/ref</a></div>
<div class="_Entity _EType_OWALinkPreview _EId_OWALinkPreview _EReadonly_1" style="color: inherit; background-color: inherit;">
<div id="LPBorder_GTaHR0cHM6Ly9naXRodWIuY29tL29wZW5qZGsvamRrL3RyZWUvbWFzdGVyL3Rlc3QvbWljcm8vb3JnL29wZW5qZGsvYmVuY2gvamF2YS91dGlsL3N0cmVhbS9vcHMvcmVm" class="LPBorder274140" style="width: 100%; margin-top: 16px; margin-bottom: 16px; position: relative; max-width: 800px; min-width: 424px;">
<table id="LPContainer274140" role="presentation" style="padding: 12px 36px 12px 12px; width: 100%; border-width: 1px; border-style: solid; border-color: rgb(200, 200, 200); border-radius: 2px;">
<tbody>
<tr valign="top" style="border-spacing: 0px;">
<td>
<div id="LPImageContainer274140" style="position: relative; margin-right: 12px; height: 120px; overflow: hidden; width: 240px;">
<a target="_blank" id="LPImageAnchor274140" href="https://github.com/openjdk/jdk/tree/master/test/micro/org/openjdk/bench/java/util/stream/ops/ref"><img id="LPThumbnailImageId274140" alt="" height="120" style="display: block;" width="240" src="https://opengraph.githubassets.com/004d92ce0313fcb0df04cee2d5ae62241a675b042bb73c5de9481333278bcfa2/openjdk/jdk"></a></div>
</td>
<td style="width: 100%;">
<div id="LPTitle274140" style="font-size: 21px; font-weight: 300; margin-right: 8px; font-family: wf_segoe-ui_light, "Segoe UI Light", "Segoe WP Light", "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; margin-bottom: 12px;">
<a target="_blank" id="LPUrlAnchor274140" href="https://github.com/openjdk/jdk/tree/master/test/micro/org/openjdk/bench/java/util/stream/ops/ref" style="text-decoration: none;">jdk/test/micro/org/openjdk/bench/java/util/stream/ops/ref at master ¡P openjdk/jdk</a></div>
<div id="LPDescription274140" style="font-size: 14px; max-height: 100px; color: rgb(102, 102, 102); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif; margin-bottom: 12px; margin-right: 8px; overflow: hidden;">
JDK main-line development https://openjdk.org/projects/jdk - openjdk/jdk</div>
<div id="LPMetadata274140" style="font-size: 14px; font-weight: 400; color: rgb(166, 166, 166); font-family: wf_segoe-ui_normal, "Segoe UI", "Segoe WP", Tahoma, Arial, sans-serif;">
github.com</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Cheers,<br>
¡Ô</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<b><br>
</b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<b>Viktor Klang</b></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Software Architect, Java Platform Group<br>
Oracle</div>
</div>
<div id="appendonsend" style="color: inherit;"></div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr style="display: inline-block; width: 98%;">
<div id="divRplyFwdMsg" dir="ltr" style="color: inherit;"><span style="font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);"><b>From:</b> Cay Horstmann <cay.horstmann@gmail.com><br>
<b>Sent:</b> Tuesday, 15 October 2024 20:19<br>
<b>To:</b> Viktor Klang <viktor.klang@oracle.com>; core-libs-dev@openjdk.org <core-libs-dev@openjdk.org><br>
<b>Subject:</b> Re: [External] : Re: Fw: New candidate JEP: 485: Stream Gatherers</span>
<div> </div>
</div>
<div style="font-size: 11pt;">Thanks Viktor, I like your concept of multiple vantage points a lot.<br>
<br>
> Implementor: "use ofGreedy to signal that this operation does not itself initiate short-circuiting"<br>
> Reviewer: "when you see ofGreedy verify that this operation does not itself initiate short-circuiting"<br>
> Debugger: "when the expectation was that the stream should be short-circuiting and isn't, one thing to look for is ofGreedy"<br>
><br>
> Implementor: "use ofSequential to signal that this operation is intended to always be executed sequentially"<br>
> Reviewer: "when you see ofSequential, understand why the operation can't/shouldn't be parallelized for parallel streams"<br>
> Debugger: "if the parallel stream is not performing as well as expected, one thing to look for is ofSequential!<br>
<br>
I just don't see how these scenarios are parallel. To me, the following  would be parallel.<br>
<br>
Scenario I: Brag about better performance<br>
<br>
As implementor, I can always go the easy route with of/of: sequential, non-greedy. It'll work, but performance may suffer. Or I can assert that I have done the extra care: ofParallel/ofGreedy.<br>
<br>
As reviewer, I see the deluxe ofParallel/ofGreedy, and I verify that the operation enables parallel execution/doesn't short circuit.<br>
<br>
As debugger, I see slow performance, and I am not surprised if it's the lame of/of.<br>
<br>
Scenario II: Warn of worse performance<br>
<br>
As implementor, I aim to produce the most performant way with of/of: parallelizable, greedy. Nice names for the good stuff. If I can't, I'll alert with ofSerial/ofShortCircuit.<br>
<br>
As reviewer, I see the coveted of/of, and I verify that the operation enables parallel execution/doesn't short circuit.<br>
<br>
As debugger, I see slow performance, and I am not surprised if it is ofSerial/ofShortCircuit. They had it coming.<br>
<br>
Either naming pair (ofParallel/ofGreedy or ofSerial/ofShortCircuit) feels consistent to me. But I find of/ofGreedy and ofSerial/of awkward to explain.<br>
<br>
Maybe just a mental block on my side. If other programmers worked with the API and found it consistent, don't mind me. I just thought to bring it up in case this has not received a lot of scrutiny. It is a pretty specialized aspect, after all.<br>
<br>
Cheers,<br>
<br>
Cay<br>
<br>
PS. I also think it would be helpful to be more explicit in the javadoc about the value of exploiting greediness. What is the sweet spot? Recognizing that nothing in the pipeline is short-circuiting and then pushing elements through without checking? Or more
 aggressive parallelization?<br>
<br>
I looked at the source code of Gatherer/Gatherers/GathererOp, and it is not obvious to me how one can see a significant performance win with greediness. Can you recommend a benchmark for me to study?<br>
<br>
--<br>
<br>
Cay S. Horstmann | <a href="https://urldefense.com/v3/__https://horstmann.com__;!!ACWV5N9M2RV99hQ!L7TUnjIXEj8etBmsbDi4Y0NIBR_DpdDkgJ_6QMR7JTEcftYTsVg6pinwac2lDODJd-lbUAcTYIMVWWLk0ej1qtAeqw$" id="OWA78e76f05-83fc-d64e-ecd9-16409390c2a5" class="OWAAutoLink" data-auth="NotApplicable">
https://urldefense.com/v3/__https://horstmann.com__;!!ACWV5N9M2RV99hQ!L7TUnjIXEj8etBmsbDi4Y0NIBR_DpdDkgJ_6QMR7JTEcftYTsVg6pinwac2lDODJd-lbUAcTYIMVWWLk0ej1qtAeqw$</a><br>
<br>
</div>
</body>
</html>