logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Empty Filters in config has performance implication
Date Wed, 08 Jul 2015 23:20:21 GMT
Hi All:

I am now profiling my JDBC driver and I was surprised to see Log4j's
CompositeFilter.filter() show up at 0.9% of CPU time when I had logging set
to INFO which only logged two events for the whole test run. The driver
does a lot of flow tracing at the TRACE level so Log4j gets called _a lot_.

In my XML config, I have a Filters element with a bunch of Filter child
elements.When I am debugging, I comment some filters in and out. Most of
the time, I am not debugging, so I have all the individual filters
commented out. The top level Filters element is still there.

If I completely remove all filters from the config (no Filters element),
then the CompositeFilter disappears from profiling.

Now that I've looked at the code, I see that the behavior is explained by:

    public static CompositeFilter createFilters(@PluginElement("Filters")
final Filter[] filters) {
        final List<Filter> filterList = filters == null || filters.length
== 0 ?
            new ArrayList<Filter>() : Arrays.asList(filters);
        return new CompositeFilter(filterList);

An XML fragment like <Filters></Filters> always creates a CompositeFilter
even though there is nothing to filter.

I'm not sure what is the best way to fix this. The CompositeFilter could
accept a null and treat it specially (not pretty or effective since
filter() still gets called a gazillion times). Ideally, the createFilters
should not even be called in the empty Filters element case.

This is too nasty and obscure to put in the FAQ so I'd like to discuss how
to fix it.


Thank you,

E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

View raw message