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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Jeremias Maerki
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

Reply | Threaded
Open this post in threaded view
|

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

Jeremias Maerki

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

Reply | Threaded
Open this post in threaded view
|

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

GlenMazza
In reply to this post by Jeremias Maerki
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).
>