On Fri, Sep 30, 2016 at 10:15 PM, David M. Lloyd <david.lloyd(a)redhat.com> wrote:
The performance problem that this trick is meant to resolve is really
a
problem in the logging backend. It *should* be faster inside of
WildFly, where JBoss LogManager is used, because that project just
checks a single volatile field for the level check... and the path to
that code *should* be inline-friendly.
Indeed, we started using this trick because of log4j 1.2, which needs
to walk the logger hierarchy in order to check the level, and it made
a significant difference there.
Nowadays I think it's pretty close to optimal in all logging
frameworks. The only nitpick is that they all use enums for the
levels, and the JIT can't inline Level.TRACE.value as it would with a
Level.TRACE_VALUE int constant. If JDK9 fixes that, then it's going to
be more or less equivalent to using a volatile "trace" field in each
class, so it should be suitable even for local read operations that
take < 200ns.
We'd probably still need to weed out some of the trace messages, as we
probably have more than 10 of them during such a read operation. I
confess that I added way too many trace logs myself, precisely because
I knew we are using a static final field and the JIT compiler doesn't
even generate code for that branch.
Cheers
Dan