You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Jeremias Maerki <de...@greenmail.ch> on 2005/06/06 09:15:34 UTC

Impact of logging on performance (was: Re: cvs commit: xml-fop/src/java/org/apache/fop/area PageViewport.java)

An explanation why the "log.isDebugEnabled()" was there and why it
should be added again (maybe not necessarily in this case since it's
only called once per page but as a general rule):

"+" operations with Strings usually results in a StringBuffer being
created the two Strings before and after the operator being combined and
then converted to a String object again. If you have multiple "+"
operator it depends on the intelligence of the JIT compiler whether it
creates only one StringBuffer or one for each "+" operation. Older VMs
always created multiple StringBuffers.

What happens without the isDebugEnabled() is that the combined String is
always (!) built (possibly multiple new String and StringBuffer
instances as well as possibly multiple calls to other methods for
building te String) and then passed into the debug() method. Only then
will the logging implementation check if the log level is sufficient to
output the log statement.

General rule of thumb: Always surround a debug log statement with a
isDebugEnabled() check if the log statement is non-trivial (i.e.
not a simple constant String).

More information:
http://jakarta.apache.org/commons/logging/api/org/apache/commons/logging/Log.html
http://logging.apache.org/log4j/docs/manual.html#performance
http://excalibur.apache.org/apidocs/org/apache/avalon/framework/logger/Logger.html
https://www.qos.ch/ac2001/F11-190.html

On 06.06.2005 07:46:00 gmazza wrote:
>   -        if (log.isDebugEnabled()) {
>   -            log.debug("[" + curPV.getPageNumberString() + (bIsBlank ? "*" : "") + "]");
>   -        }
>   -
>   -        curPV.createSpan(false);
>   +        log.debug("[" + curPV.getPageNumberString() + (bIsBlank ? "*" : "") + "]");
>            return curPV;


Jeremias Maerki


Re: Impact of logging on performance (was: Re: cvs commit: xml-fop/src/java/org/apache/fop/area PageViewport.java)

Posted by Jeremias Maerki <de...@greenmail.ch>.
On 06.06.2005 09:15:34 Jeremias Maerki wrote:
> operator it depends on the intelligence of the JIT compiler whether it

That should have been the Java Compiler, not the JIT compiler.

Jeremias Maerki


Re: Impact of logging on performance (was: Re: cvs commit: xml-fop/src/java/org/apache/fop/area PageViewport.java)

Posted by Glen Mazza <gr...@verizon.net>.
Yes, you're absolutely correct.  Up until now my "ROT" was pure line
count -- if just one, don't bother with the isDebugEnabled().  But now I see
the need to also check the parameter supplied.  BTW, if you're making
changes to the code today if you can take care of this it would be
appreciated.  Else I'll return it when I next make a CVS commit.

Thanks,
Glen

----- Original Message ----- 
>
> General rule of thumb: Always surround a debug log statement with a
> isDebugEnabled() check if the log statement is non-trivial (i.e.
> not a simple constant String).
>