<div dir="ltr">Awesome Dan! May I ask for a Pull Request: <a href="https://github.com/slaskawi/jboss-logging-perf-test">https://github.com/slaskawi/jboss-logging-perf-test</a>?<div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 3, 2016 at 2:40 PM, Dan Berindei <span dir="ltr">&lt;<a href="mailto:dan.berindei@gmail.com" target="_blank">dan.berindei@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Sebastian<br>
<br>
I modified your benchmark so that the logger and the trace field are<br>
static final and looked at the generated assembly with JITWatch [1].<br>
Based on the attached assembly listings, caching isTraceEnabled() in a<br>
constant field is &quot;infinitely faster&quot;, because there are no assembly<br>
instructions that can be traced back to the test method.<br>
<br>
JBossLogManagerLogger::<wbr>translate() is inlined in this listing, but it<br>
still goes through the switch machinery, I&#39;m guessing because the<br>
ordinal of an Enum is not considered a constant.<br>
<br>
Cheers<br>
Dan<br>
<br>
<br>
[1]: <a href="https://github.com/AdoptOpenJDK/jitwatch" rel="noreferrer" target="_blank">https://github.com/<wbr>AdoptOpenJDK/jitwatch</a><br>
<br>
On Mon, Oct 3, 2016 at 11:28 AM, Sebastian Laskawiec<br>
<div class="HOEnZb"><div class="h5">&lt;<a href="mailto:slaskawi@redhat.com">slaskawi@redhat.com</a>&gt; wrote:<br>
&gt; Hey!<br>
&gt;<br>
&gt; Please have a look at the latest perf test results [1][2]:<br>
&gt;<br>
&gt; Benchmark                             Mode  Cnt           Score<br>
&gt; Error  Units<br>
&gt; MyBenchmark.noVariable               thrpt   20   681131269.875 ±<br>
&gt; 3961932.923  ops/s<br>
&gt; MyBenchmark.<wbr>withIsTraceEnabledCheck  thrpt   20   676307984.921 ±<br>
&gt; 14305970.393  ops/s<br>
&gt; MyBenchmark.withVariable             thrpt   20  2411000894.582 ±<br>
&gt; 17382438.635  ops/s<br>
&gt;<br>
&gt; I think there is no surprise here.. using a field, which stores the result<br>
&gt; of `logger.isTraceEnabled()` evaluation is 3 times faster than other<br>
&gt; options.<br>
&gt;<br>
&gt; If anyone is interested in printing out JIT stuff, I also ran it with<br>
&gt; &quot;-XX:+PrintCompilation&quot;, &quot;-XX:+PrintCompilation2&quot; and &quot;-XX:+PrintInlining&quot;<br>
&gt; here [3].<br>
&gt;<br>
&gt; I&#39;m not a performance expert but it seems that JIT could not inline the<br>
&gt; &quot;translate&quot; method because of its size (see line 1861). However it tried<br>
&gt; several times with different optimizations (and some of them were thrown<br>
&gt; away - &quot;made not entrant&quot; messages [4]).<br>
&gt;<br>
&gt; Let&#39;s wait for James&#39; opinion on this, but I think we should address this<br>
&gt; issue on JBoss Logging/LogManager side (so I agree with David here) and make<br>
&gt; those parts inlinable (wow, does this word even exist? :D). Once this is<br>
&gt; done, we could experiment further in Infinispan codebase and see how this<br>
&gt; relates to some real world benchmarks...<br>
&gt;<br>
&gt; Thanks<br>
&gt; Sebastian<br>
&gt;<br>
&gt; [1] <a href="https://gist.github.com/slaskawi/6766b6e17c7a28ac8d8962293c48a53c" rel="noreferrer" target="_blank">https://gist.github.com/<wbr>slaskawi/<wbr>6766b6e17c7a28ac8d8962293c48a5<wbr>3c</a><br>
&gt; [2] Test repository: <a href="https://github.com/slaskawi/jboss-logging-perf-test" rel="noreferrer" target="_blank">https://github.com/slaskawi/<wbr>jboss-logging-perf-test</a><br>
&gt; [3] <a href="https://gist.github.com/slaskawi/6f317bb05539611434bc91d66924bae0" rel="noreferrer" target="_blank">https://gist.github.com/<wbr>slaskawi/<wbr>6f317bb05539611434bc91d66924ba<wbr>e0</a><br>
&gt; [4]<br>
&gt; <a href="https://www.safaribooksonline.com/library/view/java-performance-the/9781449363512/ch04.html" rel="noreferrer" target="_blank">https://www.safaribooksonline.<wbr>com/library/view/java-<wbr>performance-the/9781449363512/<wbr>ch04.html</a><br>
&gt;<br>
&gt; On Mon, Oct 3, 2016 at 7:32 AM, Sebastian Laskawiec &lt;<a href="mailto:slaskawi@redhat.com">slaskawi@redhat.com</a>&gt;<br>
&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hey!<br>
&gt;&gt;<br>
&gt;&gt; Adding James to this thread.<br>
&gt;&gt;<br>
&gt;&gt; @Dennis - I think Dan has a point here. The trick with checking a field in<br>
&gt;&gt; a class is 3 times faster. Most of the checks are done in core so they are<br>
&gt;&gt; executed multiple times per operation. Changing all those places is probably<br>
&gt;&gt; not an option.<br>
&gt;&gt;<br>
&gt;&gt; @David - Let me run a test with JBoss Log Manager and get back to you with<br>
&gt;&gt; some results. But if Dan is right, and the problem is with enum mapping, I<br>
&gt;&gt; will get similar results.<br>
&gt;&gt;<br>
&gt;&gt; Thanks<br>
&gt;&gt; Sebastian<br>
&gt;&gt;<br>
&gt;&gt; On Sat, Oct 1, 2016 at 11:53 AM, Dan Berindei &lt;<a href="mailto:dan.berindei@gmail.com">dan.berindei@gmail.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Fri, Sep 30, 2016 at 10:15 PM, David M. Lloyd &lt;<a href="mailto:david.lloyd@redhat.com">david.lloyd@redhat.com</a>&gt;<br>
&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt; &gt; The performance problem that this trick is meant to resolve is really a<br>
&gt;&gt;&gt; &gt; problem in the logging backend.  It *should* be faster inside of<br>
&gt;&gt;&gt; &gt; WildFly, where JBoss LogManager is used, because that project just<br>
&gt;&gt;&gt; &gt; checks a single volatile field for the level check... and the path to<br>
&gt;&gt;&gt; &gt; that code *should* be inline-friendly.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Indeed, we started using this trick because of log4j 1.2, which needs<br>
&gt;&gt;&gt; to walk the logger hierarchy in order to check the level, and it made<br>
&gt;&gt;&gt; a significant difference there.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Nowadays I think it&#39;s pretty close to optimal in all logging<br>
&gt;&gt;&gt; frameworks. The only nitpick is that they all use enums for the<br>
&gt;&gt;&gt; levels, and the JIT can&#39;t inline Level.TRACE.value as it would with a<br>
&gt;&gt;&gt; Level.TRACE_VALUE int constant. If JDK9 fixes that, then it&#39;s going to<br>
&gt;&gt;&gt; be more or less equivalent to using a volatile &quot;trace&quot; field in each<br>
&gt;&gt;&gt; class, so it should be suitable even for local read operations that<br>
&gt;&gt;&gt; take &lt; 200ns.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; We&#39;d probably still need to weed out some of the trace messages, as we<br>
&gt;&gt;&gt; probably have more than 10 of them during such a read operation. I<br>
&gt;&gt;&gt; confess that I added way too many trace logs myself, precisely because<br>
&gt;&gt;&gt; I knew we are using a static final field and the JIT compiler doesn&#39;t<br>
&gt;&gt;&gt; even generate code for that branch.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Cheers<br>
&gt;&gt;&gt; Dan<br>
&gt;&gt;&gt; ______________________________<wbr>_________________<br>
&gt;&gt;&gt; infinispan-dev mailing list<br>
&gt;&gt;&gt; <a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
&gt;&gt;&gt; <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>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt; ______________________________<wbr>_________________<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" rel="noreferrer" target="_blank">https://lists.jboss.org/<wbr>mailman/listinfo/infinispan-<wbr>dev</a><br>
</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>