<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Jan,<div class=""><br class=""></div><div class="">Thanks for the detailed reply. TBH I didn't spend much time on the test so your comments are appropriate. I wrote the test after JFR reported <span style="caret-color: rgb(36, 41, 47); color: rgb(36, 41, 47); font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace; font-size: 11.899999618530273px; background-color: rgba(175, 184, 193, 0.2);" class="">SwitchBootstrap.typeSwitch</span> as a hotspot in a project I'm working on. I think different tests getting different lengths doesn't really poison the tests as both implementations have the same chances for list sizes and content.</div><div class=""><div><br class=""></div><div>> I wonder how much effect has the use of ConcurrentHashMap</div><div><br class=""></div><div>I tried the test with both a simple HashMap and ConcurrentHashMap and the delta was similar as I recall.</div><div><br class=""></div><div>PR 9779 looks promising. Anyway, as a Java user I would expect that the compiler can write better code than I can manually FWIW.</div><div><br class=""></div><div>Cheers.</div><div><br class=""></div><div>-Jordan</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 11, 2022, at 1:26 PM, Jan Lahoda <<a href="mailto:jan.lahoda@oracle.com" class="">jan.lahoda@oracle.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">
  
  <div class=""><p class="">Hi Jordan,</p><p class=""><br class="">
    </p><p class="">Thanks for the report. Yes, the performance of various pattern
      matching switches is something that we'd like to improve, which is
      a task that will probably take a while. Currently, one PR relevant
      to your benchmark is:</p><p class=""><a class="moz-txt-link-freetext" href="https://github.com/openjdk/jdk/pull/9779">https://github.com/openjdk/jdk/pull/9779</a></p><p class=""><br class="">
    </p><p class="">Looking at the benchmark, I have a few comments/questions:</p><p class="">1. I see the "Data" generate the test List of a random length
      between 1000 and 2000, but as far as I can tell, different
      testcases will get a List of a different length. So the testcases
      are not really the same, as their input has a different length. Do
      I miss something here?</p><p class="">2. The actual content of the List is also random, but, again, the
      content is not the same for all the testcases, which I believe
      could skew the results (consider input data which could have a
      majority of Fruit.Apple, and a different set of data which would
      have a majority of Fruit.Pear - the tasks to solve this is not the
      same). The effect of this is probably limited, though.<br class="">
    </p><p class="">3. The test uses 4 threads, but when I run it with this setting,
      the error margins are very wide, making the results much less
      reliable (per my understanding). Which may be a consequence of the
      limited amount (4 physical) of cores available on my laptop.</p><p class=""><br class="">
    </p><p class="">I've tweaked the test to use input data of length 1000 for all
      cases, and new Random(0) to generate the data.</p><p class=""><br class="">
    </p><p class="">The for one thread (testEnhancedSwitch uses the code from PR
      9779, testEnhancedSwitchLegacy uses the code currently in the
      mainline, testManualSwitch is the same as in your testcase):</p><p class="">TestEnhancedSwitch.testEnhancedSwitch        thrpt    5  
      95020.310 ±  689.833  ops/s<br class="">
      TestEnhancedSwitch.testEnhancedSwitchLegacy  thrpt    5  
      68175.714 ± 2245.512  ops/s<br class="">
      TestEnhancedSwitch.testManualSwitch          thrpt    5 
      102640.203 ± 2384.880  ops/s<br class="">
    </p><p class="">And for two threads:</p><p class="">TestEnhancedSwitch.testEnhancedSwitch        thrpt    5 
      47714.842 ± 2206.843  ops/s<br class="">
      TestEnhancedSwitch.testEnhancedSwitchLegacy  thrpt    5  47080.128
      ± 1679.960  ops/s<br class="">
      TestEnhancedSwitch.testManualSwitch          thrpt    5  41116.334
      ± 4938.590  ops/s<br class="">
    </p><p class=""><br class="">
    </p><p class="">(In the multi threaded mode, I wonder how much effect has the use
      of ConcurrentHashMap.)</p><p class=""><br class="">
    </p><p class="">Thanks,</p><p class="">    Jan</p><p class=""><br class="">
    </p>
    <div class="moz-cite-prefix">On 10. 08. 22 12:04, Jordan Zimmerman
      wrote:<br class="">
    </div>
    <blockquote type="cite" cite="mid:D4C8E4D0-3FEB-4F4B-A863-0B44CFC0B13F@jordanzimmerman.com" class="">
      
      Hi Folks,
      <div class=""><br class="">
      </div>
      <div class="">I've been experimenting with Pattern Matching for
        switch (Third Preview). I noticed that the performance of these
        enhanced switches is far worse than manual matching. Is this due
        to this only being a preview and optimizations have yet to be
        done? Anyway, I thought I'd mention what I found as an FYI.</div>
      <div class=""><br class="">
      </div>
      <div class="">Here's the jmh benchmark I used:</div>
      <div class=""><span class="Apple-tab-span" style="white-space:pre">     </span></div>
      <div class=""><span class="Apple-tab-span" style="white-space:pre">     </span><a href="https://gist.github.com/Randgalt/a68ceee62cd8127431cbe6e7afbfdf44" class="moz-txt-link-freetext" moz-do-not-send="true">https://gist.github.com/Randgalt/a68ceee62cd8127431cbe6e7afbfdf44</a></div>
      <div class=""><br class="">
      </div>
      <div class="">Here are the results:</div>
      <div class=""><br class="">
      </div>
      <div class="">
        <div class=""><font class="" face="Courier New">Benchmark      
                                    Mode  Cnt      Score       Error
             Units</font></div>
        <div class=""><font class="" face="Courier New">TestEnhancedSwitch.testEnhancedSwitch
             thrpt    5  30789.482 ± 17667.365  ops/s</font></div>
        <div class=""><font class="" face="Courier New">TestEnhancedSwitch.testManualSwitch
               thrpt    5  44651.612 ±  5135.641  ops/s</font></div>
      </div>
      <div class=""><br class="">
      </div>
      <div class="">Cheers.</div>
      <div class=""><br class="">
      </div>
      <div class="">-Jordan</div>
    </blockquote>
  </div>

</div></blockquote></div><br class=""></div></body></html>