<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p><br>
</p>
<div class="moz-cite-prefix">On 24/10/2023 11:22, Tagir Valeev
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CAE+3fjbrsL4yVienVNrox5rq0OLeTTKhJkK-F0GwH4xcTHGCZQ@mail.gmail.com">
<pre style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace"><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal">With -g the measured time is about 1800ms, while without -g it's about 6ms. That's because when lambdas are deduplicated, type profile for map() method is clean, and the whole stream can be inlined, and even the loop could be likely replaced with a constant. When lambdas are not deduplicated, this is not the case: type profile is polluted, and the whole stream cannot be inlined. So, deduplication can actually improve the performance, at least in such extreme cases.</span></pre>
</blockquote>
Very interesting results - thanks! I believe it works well because
when deduplication kicks in, the body is _really_ identical, so
there's no value in keeping separate profiling info for the three
lambdas. Well, maybe, maybe not. If your lambda has some conditional
code (`if (cond) ...`) and one lambda is always used where cond =
true and the other lambda is always used where cond = false, this
might be a problem as the profile of the deduplicate lambda might
get polluted. So I'm not sure how reliably this technique would
actually work out in practice as a way to improve performance.<br>
<blockquote type="cite" cite="mid:CAE+3fjbrsL4yVienVNrox5rq0OLeTTKhJkK-F0GwH4xcTHGCZQ@mail.gmail.com">
<pre style="color:rgb(8,8,8);font-family:"JetBrains Mono",monospace"><span style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif;white-space:normal">By the way, while experimenting with this sample, I've noticed that deduplication of this particular code is broken since Java 18 (the code performs slowly both with and without -g, and reading the bytecode confirms that no deduplication is done). Should I report, or probably there's no interest in supporting this feature?</span></pre>
</blockquote>
<p>Oh - I wasn't aware of this issue - regardless of what we wanna
do with this feature moving forward, filing a bug is always the
right thing to do, to make sure it doesn't fall off the radar.</p>
<p>Thanks<br>
Maurizio<br>
</p>
</body>
</html>