<div dir="ltr"><div><div><div><div><div><div><div><div><div><div>I understand the impact of this, but we should keep in mind that there are some important points where it is worse if you can&#39;t change the logging on the fly for a few moments to check something and switch back.<br><br></div>For the test my understanding is that you use<br></div>- the logger.tracef direct<br></div>- check logger.isTraceEnabled() first<br><br></div>I see the variable stored but not used - or am I wrong and the benchmark test do something extra?<br></div><div><br></div><div><br></div>So interesting would be the difference between<br></div>- log.trace(&quot;xyz&quot;)<br></div>- if(log.isTraceEnabled) log.trace(&quot;xyz&quot;)<br>- log.tracef(&quot;xyz %s&quot;, var)<br>- if(log.isTraceEnabled) log.tracef(&quot;xyz %s&quot;,var)<br></div>and the construct with storing the log level in a static field<br></div>- boolean isTrace=log.isTraceEnabled()<br></div>   if(isTrace) log.tracef(&quot;xyz %s&quot;,var)<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 30, 2016 at 8:53 AM, Sebastian Laskawiec <span dir="ltr">&lt;<a href="mailto:slaskawi@redhat.com" target="_blank">slaskawi@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey!<div><br></div><div>A while ago I asked Radim and Dan about these kind of constructs [1]:</div><div><br></div><div>private boolean trace = logger.isTraceEnabled(); //stored in a field<br></div><div><br></div><div>... called in some method ...</div><div>    if(trace)</div><div>        logger.tracef(...);</div><div>...</div><div><br></div><div>At first they seemed wrong to me, because if one changes logging level (using JMX for example), the code won&#39;t notice it. I also though it&#39;s quite ok to use tracef directly, because JIT will inline and optimize it.</div><div><br></div><div>Unfortunately my benchmarks [2] show that I was wrong. Logger#tracef indeed checks if the logging level is enabled but since JBoss Logging may use different backends, the check is not trivial and is not inlined (at least with default settings). The performance results look like this:</div><div><div>Benchmark                  Mode  Cnt           Score          Error  Units</div><div>MyBenchmark.noVariable    thrpt   20   <b>717252060.124</b> ± 13420522.229  ops/s</div><div>MyBenchmark.withVariable  thrpt   20  <b>2358360244.627</b> ± 50214969.572  ops/s</div></div><div><br></div><div>So if you even see a construct like this: logger.debuf or logger.tracef - make sure you check if the logging level is enabled (and the check result is stored in a field). </div><div><br></div><div>That was a bit surprising and interesting lesson :D</div><div><br></div><div>Thanks</div><div>Sebastian</div><div><br></div><div>[1] <a href="https://github.com/infinispan/infinispan/pull/4538#discussion_r80666086" target="_blank">https://github.com/<wbr>infinispan/infinispan/pull/<wbr>4538#discussion_r80666086</a></div><div>[2] <a href="https://github.com/slaskawi/jboss-logging-perf-test" target="_blank">https://github.com/<wbr>slaskawi/jboss-logging-perf-<wbr>test</a></div></div>
<br>______________________________<wbr>_________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a><br></blockquote></div><br></div>