logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christophe de VIENNE <cdevie...@alphacent.com>
Subject Re: LOG4CXX macros
Date Thu, 12 Aug 2004 16:22:58 GMT
Curt Arnold wrote:

> In GCC, you can use __builtin_expect to hint to the optimizer the 
> expected value of a expression 
> (http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#Other-Builtins). 
>  So if LOG4CXX_DEBUG evaluated to:
>
> if (__builtin_expect(log.isDebugEnabled(), 0)) {
>    log.forceLog(Level::DEBUG, msg);
> }
>
> Then the compiler would know that it would be relatively unlikely for 
> the body of the if to be executed and could optimize appropriately.  
> If it has an impact on the performance, it should make the code run 
> faster when the debug messages are disabled and slower when they are 
> enabled.  __builtin_expect doesn't actually call anything.



Thanks it's much more clear now.
It seems to me that no unwanted side-effect can result of such a change. 
So I'd agree to make it (the way you propose to implement looks fine), 
although I'd be very curious to know how the optimiser can make it faster.
I'd also be interested in a measure of the performance gain.

Christophe

Mime
View raw message