<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;">This doesn’t look correct:<div><br></div><div><table class="diff-table js-diff-table tab-size" data-tab-size="8" data-diff-anchor="diff-314e483e41a8dd49577b207c12683b369ab87b6de6da289b9f7e89aae5f412cb" data-paste-markdown-skip="" style="font-variant-caps: normal; border-spacing: 0px; width: 1079.837036px; tab-size: 8; caret-color: rgb(5, 12, 20); color: rgb(5, 12, 20); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; font-size: 14.000001px;"><tbody style="box-sizing: border-box;"><tr data-hunk="ec9d10a0b953d5d3106d8a74851268b11fb7a2759f4a566f0c53ec0faa5f49c0" class="show-top-border" style="box-sizing: border-box;"><td class="blob-code blob-code-addition js-file-line is-hovered" style="box-sizing: border-box; padding: 0px 10px 0px 22px; position: relative; line-height: 20px; vertical-align: top; outline: transparent dotted 1px;"><span class="blob-code-inner blob-code-marker" data-code-marker="+" style="box-sizing: border-box; display: table-cell; overflow: visible; font-family: var(--fontStack-monospace, ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace); font-size: 12px; overflow-wrap: anywhere; white-space: pre-wrap;"> <span class="pl-k" style="box-sizing: border-box;">for</span> (<span class="pl-smi" style="box-sizing: border-box;">int</span> <span class="pl-s1" style="box-sizing: border-box;">i</span> = <span class="pl-c1" style="box-sizing: border-box;">0</span>; <span class="pl-s1" style="box-sizing: border-box;">i</span> < <span class="pl-c1" style="box-sizing: border-box;">100_000</span>; <span class="pl-s1" style="box-sizing: border-box;">i</span>++) {</span></td></tr><tr data-hunk="ec9d10a0b953d5d3106d8a74851268b11fb7a2759f4a566f0c53ec0faa5f49c0" class="show-top-border" style="box-sizing: border-box;"><td class="blob-code blob-code-addition js-file-line" style="box-sizing: border-box; padding: 0px 10px 0px 22px; position: relative; line-height: 20px; vertical-align: top; outline: transparent dotted 1px;"><span class="blob-code-inner blob-code-marker" data-code-marker="+" style="box-sizing: border-box; display: table-cell; overflow: visible; font-family: var(--fontStack-monospace, ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace); font-size: 12px; overflow-wrap: anywhere; white-space: pre-wrap;"> <span class="pl-s1" style="box-sizing: border-box;">bh</span>.<span class="pl-en" style="box-sizing: border-box;">consume</span>(<span class="pl-c1" style="box-sizing: border-box;">MISSING</span>.<span class="pl-en" style="box-sizing: border-box;">orElse</span>(<span class="pl-s" style="box-sizing: border-box;">"hello world"</span>));</span></td></tr><tr data-hunk="ec9d10a0b953d5d3106d8a74851268b11fb7a2759f4a566f0c53ec0faa5f49c0" class="show-top-border" style="box-sizing: border-box;"><td class="blob-code blob-code-addition js-file-line" style="box-sizing: border-box; padding: 0px 10px 0px 22px; position: relative; line-height: 20px; vertical-align: top; outline: transparent dotted 1px;"><span class="blob-code-inner blob-code-marker" data-code-marker="+" style="box-sizing: border-box; display: table-cell; overflow: visible; font-family: var(--fontStack-monospace, ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace); font-size: 12px; overflow-wrap: anywhere; white-space: pre-wrap;"> }
why are you looping 100k times there?</span></td></tr></tbody></table><div><br><blockquote type="cite"><div>On Jun 24, 2025, at 11:44 AM, Johan Sjolen <johan.sjolen@oracle.com> wrote:</div><br class="Apple-interchange-newline"><div><div>Hi Aleksey,<br><br>I re-wrote my benchmarks to use JMH and I used Blackhole::consume instead of the S.o.println. The entire point of the println was to signal to the compiler 'this has to happen'. I kept the 100k iterations, as I didn't want the setup of the 100 dynamic bindings to dominate (or perhaps they are? Not sure).<br><br>I ended up with the following results:<br><br><br>(This is the test of just doing MISSING.orElse)<br>Result "org.openjdk.bench.java.lang.ScopedValues.ScopedValuesAreFasT":<br> 815142.530 ±(99.9%) 17764.324 ns/op [Average]<br> (min, avg, max) = (790345.594, 815142.530, 835566.013), stdev = 11750.000<br> CI (99.9%): [797378.206, 832906.854] (assumes normal distribution)<br><br>(This is the test with MISSING.orElse within the 100 dynamic bindings)<br>Result "org.openjdk.bench.java.lang.ScopedValues.ScopedValuesAreSlow":<br> 18847997.203 ±(99.9%) 587930.099 ns/op [Average]<br> (min, avg, max) = (18176298.357, 18847997.203, 19523500.462), stdev = 388879.358<br> CI (99.9%): [18260067.104, 19435927.301] (assumes normal distribution)<br><br><br>That's 815142 ns/op vs 18847997ns/op, a pretty large diff still ('contested' case takes 23x longer).<br><br>Am I messing up my benchmarks once again, but in some different way?<br><br>Here's the branch and source: https://github.com/openjdk/jdk/compare/master...jdksjolen:jdk:scopedvaluejmhs<br><br>I just put the benchmark into the pre-existing ScopedValues.java, should just be a copy and paste and be done if you've got a JDK build set up.<br>The tests are run on linux-aarch64.<br><br>________________________________________<br>From: Aleksey Shipilev <shipilev@amazon.de><br>Sent: Tuesday, June 24, 2025 18:08<br>To: Johan Sjolen; Robert Engels<br>Cc: loom-dev@openjdk.org<br>Subject: Re: ScopedValue performance declines as number of dynamic bindings increases<br><br>On 24.06.25 18:01, Johan Sjolen wrote:<br><blockquote type="cite">Oooh, that could explain the issue completely. I didn't think about that at all.<br>The issue basically disappears when compiling first, let me see what happens with a JMH benchmark as well.<br></blockquote><br>I predict JMH would show the same thing.<br><br>javac is not very fast when cold; this is also why we use it as go-to example in AOT cache studies.<br>I would also expect compiling deeply nested lambdas (like in ScopedTest.java) makes the javac code<br>fairly recursive, which again plays interestingly with JIT compilation. It is still<br>actionable/interesting to figure out what can be improved there. Looks fairly weird we spend >3<br>seconds compiling a seemingly "easy" source. Submit a tools/javac RFE, let compiler folks have fun<br>with it?<br><br>-Aleksey<br><br><br><br>Amazon Web Services Development Center Germany GmbH<br>Tamara-Danz-Str. 13<br>10243 Berlin<br>Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss<br>Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B<br>Sitz: Berlin<br>Ust-ID: DE 365 538 597<br></div></div></blockquote></div><br></div></body></html>