<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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 Daniel,<br>
<br>
Making changes locally and use the tests to verify your assumptions is a great way to validate your understanding.</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);">
Then you can use the benches to validate the performance impact of your modifications, then it becomes easier to discuss the pros/cons of potential changes here on the list.</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);">
That's what I'd do if I were in your shoes. 🙂</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 id="Signature" style="color: inherit;">
<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"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Daniel Avery <danielaveryj@gmail.com><br>
<b>Sent:</b> Friday, 17 January 2025 18:06<br>
<b>To:</b> Viktor Klang <viktor.klang@oracle.com><br>
<b>Cc:</b> core-libs-dev@openjdk.org <core-libs-dev@openjdk.org><br>
<b>Subject:</b> [External] : Re: Minor optimizations / questions about stream implementation</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hi Viktor.
<div><br>
<div>I guess for 1-4 I'm just looking for a quick eyeball to check if my takeaways are valid, nothing too committal.</div>
<div><br>
</div>
<div>I'm a little more interested in 5, because I'm currently building a document that is attempting to capture how the stream internals fit together, including visualizing stream performance characteristics. How op flags are set/cleared/propagated plays a
big part in what I've prepared. I want to make sure I don't oversimplify how they work.</div>
</div>
<div><br>
</div>
<div>I have not attempted to make/test changes to the source. I guess I didn't presume I could contribute in that way, but I can look into it if you think it's worth it :)</div>
<div><br>
</div>
<div>Thanks,</div>
<div>Daniel</div>
</div>
<br>
<div class="x_gmail_quote x_gmail_quote_container">
<div dir="ltr" class="x_gmail_attr">On Fri, Jan 17, 2025 at 3:32 AM Viktor Klang <<a href="mailto:viktor.klang@oracle.com">viktor.klang@oracle.com</a>> wrote:<br>
</div>
<blockquote class="x_gmail_quote" style="margin:0px 0px 0px 0.8ex; border-left:1px solid rgb(204,204,204); padding-left:1ex">
<div class="x_msg-5829456082169612697">
<div dir="ltr">
<div style="text-align:left; text-indent:0px; margin:0px; font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Hi Daniel,<br>
<br>
Thanks for your patience.</div>
<div style="text-align:left; text-indent:0px; margin:0px; font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="text-align:left; text-indent:0px; margin:0px; font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
What kind of feedback/responses are you looking for primarily?</div>
<div style="text-align:left; text-indent:0px; margin:0px; font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="text-align:left; text-indent:0px; margin:0px; font-family:Aptos,Aptos_EmbeddedFont,Aptos_MSFontService,Calibri,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Have you attempted to make changes and run any of the openjdk stream benches (after running the tests)?</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 id="x_m_-8970677703542791311Signature" style="color:inherit">
<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="x_m_-8970677703542791311appendonsend"></div>
<hr style="display:inline-block; width:98%">
<div id="x_m_-8970677703542791311divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> core-libs-dev <<a href="mailto:core-libs-dev-retn@openjdk.org" target="_blank">core-libs-dev-retn@openjdk.org</a>>
on behalf of Daniel Avery <<a href="mailto:danielaveryj@gmail.com" target="_blank">danielaveryj@gmail.com</a>><br>
<b>Sent:</b> Friday, 10 January 2025 04:01<br>
<b>To:</b> <a href="mailto:core-libs-dev@openjdk.org" target="_blank">core-libs-dev@openjdk.org</a> <<a href="mailto:core-libs-dev@openjdk.org" target="_blank">core-libs-dev@openjdk.org</a>><br>
<b>Subject:</b> Minor optimizations / questions about stream implementation</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hi,
<div><br>
</div>
<div>I recently finished a deep-dive through the code in java.util.stream, and came across a few corners that stuck out to me as being odd, in a "small missed opportunity" kind of way. I figured I'd raise them here just in case any are legitimate, or I could
get some better insight. I am looking at JDK 24 [build 30] (<a href="https://urldefense.com/v3/__https://github.com/openjdk/jdk/tree/jdk-24*2B30/src/java.base/share/classes/java__;JQ!!ACWV5N9M2RV99hQ!MBErb0Xr4lxhgwlShTvhe9c5ywsXfa99Pypv8ZxvWaoYVgN4uhE863O8Sdhea8_nE7bwfzMoY0ziqdBhduxMiCb7$" target="_blank">https://github.com/openjdk/jdk/tree/jdk-24%2B30/src/java.base/share/classes/java</a>).</div>
<div><br>
</div>
<div>1. AbstractPipeline.wrap() is passed isParallel(), which ultimately (only) plays into determining if StreamSpliterators.AbstractWrappingSpliterator is allowed to split. It looks like the code could be more lenient, and instead pass (isParallel() || !hasAnyStateful()),
i.e. allow splitting the spliterator() from sequential streams that do not have stateful ops.</div>
<div><br>
</div>
<div>2. It looks like StreamSpliterators.UnorderedSliceSpliterator.trySplit() should disable splitting if (permitStatus == NO_MORE), instead of (permits.get() == 0). As is, it would appear to unnecessarily disable splitting after skipping, in the skip-only
case.</div>
<div><br>
</div>
<div>3. It looks like SortedOps could override opEvaluateParallelLazy to no-op in the already-sorted case, similar to DistinctOps in the already-distinct case.</div>
<div><br>
</div>
<div>4. It looks like SliceOps.makeRef() could fuse adjacent skip()/limit() ops (though I could see that being an overly niche optimization, especially if it makes linked/consumed handling painful).</div>
<div><br>
</div>
<div>5. It looks like there is some dead code in StreamOpFlag? I don't see a path where isPreserved() would return true in practice (it appears to only be called in exactly 2 'minor optimization' places: SliceTask.doLeaf() and DropWhileTask.doLeaf()). With
the way StreamOpFlag.combineOpFlags() works, it looks like in practice 0b00 is used to preserve, rather than 0b11. I also don't see Type.OP, Type.TERMINAL_OP, or Type.UPSTREAM_TERMINAL_OP being used anywhere. I assume some of the methods here are intended
for tests only (isStreamFlag(), canSet())... But given how much of this class I'm not seeing being used, I'm wondering if I'm just missing something.<br>
<br>
Thank you,<br>
Daniel</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</body>
</html>