<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">https://github.com/infinispan/infinispan/pull/4538#discussion_r80666086</a></div><div>[2] <a href="https://github.com/slaskawi/jboss-logging-perf-test">https://github.com/slaskawi/jboss-logging-perf-test</a></div></div>