<p>Manik, I believe the constants are interned the moment the class is loaded, so there&#39;s no extra work to pass int to the trace method.<br>
</p>
<div class="gmail_quote">Īn data de 07.12.2011 12:43, &quot;Manik Surtani&quot; &lt;<a href="mailto:manik@jboss.org">manik@jboss.org</a>&gt; a scris:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Bringing this thread up again, is it really true to say that<br>
<br>
   if (trace) log.trace(&quot;blah&quot;)<br>
<br>
is as cheap as<br>
<br>
  log.trace(&quot;blah&quot;)<br>
<br>
?<br>
<br>
In the former, with tracing disabled, nothing happens after the condition check.  In the latter, you still construct a String &quot;blah&quot;, and even if there is no complex interpolation or message construction, the basic String message is still constructed (and starts to take up PermGen space too, as literals are interned [1]).<br>

<br>
So the case for the if (trace) pattern still stands IMO.<br>
<br>
Cheers<br>
Manik<br>
<br>
[1] <a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#intern()" target="_blank">http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#intern()</a><br>
&quot;All literal strings and string-valued constant expressions are interned.&quot;<br>
<br>
On 28 Sep 2011, at 17:41, David M. Lloyd wrote:<br>
<br>
&gt; On 09/28/2011 11:35 AM, Mircea Markus wrote:<br>
&gt;&gt; Hi,<br>
&gt;&gt;<br>
&gt;&gt; I&#39;m not aware of any convention on using trace vs log.isTraceEnabled() to guard the trace statements.<br>
&gt;&gt;<br>
&gt;&gt; if (trace) log.trace(&quot;some request related stuff&quot;)<br>
&gt;&gt; vs<br>
&gt;&gt; if (log.isTraceEnabled()) log.trace(&quot;some request related stuff&quot;);<br>
&gt;&gt;<br>
&gt;&gt; The former is more efficient, but cannot be managed at runtime. It seems to be the preferred form, so shall we stick with it?<br>
&gt;<br>
&gt; If you&#39;re using the jboss-logging API, and your log statement does not<br>
&gt; do any interpolation, then it is just as fast to do any of the following<br>
&gt; (with no if):<br>
&gt;<br>
&gt;    log.trace(&quot;blah&quot;);<br>
&gt;    log.tracef(&quot;the %s happened to %s&quot;, foo, bar);<br>
&gt;    log.tracev(&quot;the {0} happened to {1}&quot;, foo, bar);<br>
&gt;<br>
&gt; In the case where trace logging is disabled, these are exactly as<br>
&gt; efficient as the if (log.isTraceEnabled()) variants.  In the case where<br>
&gt; it is enabled, it is marginally more efficient (though the trace log<br>
&gt; itself is substantially more expensive of course).<br>
&gt;<br>
&gt; Overall I&#39;d avoid the &quot;if&quot; forms unless you&#39;re doing complex interpolation:<br>
&gt;<br>
&gt;    log.trace(&quot;Foo &quot; + bar + &quot; baz &quot; + zap);<br>
&gt;    log.tracef(&quot;the %s happened to %s&quot;, fooMethod().barMethod(), bar);<br>
&gt;<br>
&gt; ...both of which incur the expense of the expression resolution even if<br>
&gt; the log message is ultimately discarded.<br>
&gt; --<br>
&gt; - DML<br>
&gt; _______________________________________________<br>
&gt; infinispan-dev mailing list<br>
&gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
<br>
--<br>
Manik Surtani<br>
<a href="mailto:manik@jboss.org">manik@jboss.org</a><br>
<a href="http://twitter.com/maniksurtani" target="_blank">twitter.com/maniksurtani</a><br>
<br>
Lead, Infinispan<br>
<a href="http://www.infinispan.org" target="_blank">http://www.infinispan.org</a><br>
<br>
<br>
<br>
<br>
_______________________________________________<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" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
</blockquote></div>