directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lecharny <>
Subject Re: [Logging] Is this required if we use substitutions
Date Fri, 06 Jun 2008 07:30:04 GMT

in this very case, the DN won't be parsed, as the getUpName() just 
returns the inner String.

The difference between a direct call to log.debug and the if (IS_DEBUG) 
is that if the IS_DEBUG is set to false, then the compiler will simply 
not do the test at all, because it's a static variable, and it will be 
optimized internally by a removal of this portion of the code.

So the "is (IF_DEBUG)" will be faster than a call to the LOG.debug() 
method, sparing the call.

Keep in mind that it's marginal, but in some places where we have a lot 
of LOGs, this is interesting to use this trick.

Also this is valid for DEBUG mode, not for info, as it won't be anymore 
possible to activate the log dynamically without restarting the server, 
as the bytecode will not contain the call anymore.

Ersin Er wrote:
> Hi,
> I think this is more of an issue of parameter evaluation than string
> concatenation. If you do not do a IS_DEBUG check first, then even if the
> debug is not enabled, opContext.getEntry() and opContext.getDn().getUpName()
> will have to be evaluated first (before the debug method is called). So if
> these are particularly expensive operations you may have a serious CPU cycle
> loss. The example here is not perfect for demostrating this situation but if
> one of the parameters was calculated via a DN parsing operation then the
> result (without IS_DEBUG) would be quite bad.
> Greetings,
> On Fri, Jun 6, 2008 at 7:40 AM, Alex Karasulu <> wrote:
>> Emmanuel,
>> I see in some places you protect calls to LOG.debug() for example with a
>> IS_DEBUG conditional like so:
>>         if ( IS_DEBUG )
>>         {
>>             LOG.debug( "Adding the entry {} for DN = '{}'",
>> opContext.getEntry(), opContext.getDn().getUpName() );
>>         }
>> If the {} based substitution is used, then does this not protect us from
>> additional String concatenation?  Is the above more efficient than:
>>          LOG.debug( "Adding the entry {} for DN = '{}'",
>> opContext.getEntry(), opContext.getDn().getUpName() );
>> Thanks,
>> Alex

cordialement, regards,
Emmanuel L├ęcharny

View raw message