xmlgraphics-fop-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremias Maerki <dev.jerem...@greenmail.ch>
Subject Impact of logging on performance (was: Re: cvs commit: xml-fop/src/java/org/apache/fop/area PageViewport.java)
Date Mon, 06 Jun 2005 07:15:34 GMT
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:

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

View raw message