<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p>In times past, there were places in javac when `instanceof` was
      *not* a substitute for checking the tag.</p>
    <p>We've probably gotten rid of those cases by now, but as a general
      coding pattern, I note that for end users writing code like
      annotation processors, the problem still remains if using other
      compilers.</p>
    <p>-- Jon<br>
    </p>
    <div class="moz-cite-prefix">On 2/21/23 7:30 PM, Archie Cobbs wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CANSoFxsiY_btJ7ues5GmsnyXQ4uXVC_6GZHYYXi=8Utsvs-eiQ@mail.gmail.com">
      
      <div dir="ltr">
        <div dir="ltr">On Tue, Feb 21, 2023 at 6:24 PM <a href="mailto:christoph.dreis@freenet.de" moz-do-not-send="true" class="moz-txt-link-freetext">christoph.dreis@freenet.de</a>
          <<a href="mailto:christoph.dreis@freenet.de" moz-do-not-send="true" class="moz-txt-link-freetext">christoph.dreis@freenet.de</a>>
          wrote:</div>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
            0.8ex;border-left:1px solid
            rgb(204,204,204);padding-left:1ex">
            <div class="msg1593643003198317397">
              <div style="overflow-wrap: break-word;" lang="DE">
                <div class="m_1593643003198317397WordSection1"><span style="color:rgb(36,41,47)" lang="EN-US">I'm
                    currently profiling some compilation phases of
                    internal projects and noticed in allocation profiles
                    that </span><code><span style="font-family:"Calibri",sans-serif;color:rgb(36,41,47)" lang="EN-US">Symtab.lookupPackage</span></code><span style="color:rgb(36,41,47)" lang="EN-US"> takes up
                    ~2% overall. The majority of this is spent in </span><code><span style="font-family:"Calibri",sans-serif;color:rgb(36,41,47)" lang="EN-US">.stream().anyMatch()</span></code><span style="color:rgb(36,41,47)" lang="EN-US"> usages to
                    find out if the given module symbol depends on the
                    unnamed module.</span></div>
              </div>
            </div>
          </blockquote>
          <div><br>
          </div>
          <div>Straightforward patch, but it's disappointing that
            unrolling a <span style="font-family:monospace">Stream</span>
            into the equivalent <span style="font-family:monospace">for</span>
            loop makes it noticeably faster (how much?).</div>
          <div><br>
          </div>
          <div>This also brings up larger philosophical questions about
            code style vs. performance. If using a <span style="font-family:monospace">Stream</span> somewhere
            makes for more clean/elegant/understandable code, but is
            slower, how to weigh the trade-off? Maybe this has been
            discussed before on this list before I joined. Maybe we
            should assign this bug to the hotspot group :)<br>
          </div>
          <div><br>
          </div>
          <div>On this same topic, this pattern which appears constantly
            in the compiler always makes me kind of quizzical:</div>
          <div><br>
          </div>
          <div style="margin-left:40px"><span style="font-family:monospace">JCExpression expr =
              TreeInfo.skipParens(tree.expr);<br>
              if (expr.hasTag(APPLY)) {<br>
                  JCMethodInvocation apply = (JCMethodInvocation)expr;</span></div>
          <div style="margin-left:40px"><span style="font-family:monospace">    ...</span></div>
          <div style="margin-left:40px"><span style="font-family:monospace">}</span><br>
          </div>
          <div><br>
          </div>
        </div>
        <div>Is <span style="font-family:monospace">instanceof</span>
          really that much slower? Maybe it was once, long ago, and this
          is a legacy thing?<br>
        </div>
        <div><br>
        </div>
        <div>-Archie<br>
        </div>
        <div>
          <div><br>
            -- <br>
            <div dir="ltr" class="gmail_signature">Archie L. Cobbs<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
  </body>
</html>