You might be able to optimize this a bit by replacing new ArrayList<Filter>()
with Collections.emptyList() On Thu, Jul 9, 2015 at 1:20 AM, Gary Gregory <[email protected]> wrote: > 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: > > @PluginFactory > 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. > > Thoughts? > > Thank you, > Gary > > -- > E-Mail: [email protected] | [email protected] > Java Persistence with Hibernate, Second Edition > <http://www.manning.com/bauer3/> > 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 > -- [image: MagineTV] *Mikael Ståldal* Senior backend developer *Magine TV* [email protected] Regeringsgatan 25 | 111 53 Stockholm, Sweden | www.magine.com Privileged and/or Confidential Information may be contained in this message. If you are not the addressee indicated in this message (or responsible for delivery of the message to such a person), you may not copy or deliver this message to anyone. In such case, you should destroy this message and kindly notify the sender by reply email.
