Issue Details (XML | Word | Printable)

Key: LOGCXX-13
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Curt Arnold
Reporter: Curt Arnold
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Log4cxx

Add branch optimization hint to LOG4CXX_DEBUG macro

Created: 23/Aug/04 09:04 PM   Updated: 23/Aug/04 09:09 PM
Return to search
Component/s: None
Affects Version/s: 0.9.7
Fix Version/s: 0.10.0

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works logcxx-13.patch 2004-08-23 09:08 PM Curt Arnold 1 kB

Resolution Date: 23/Aug/04 09:09 PM


 Description  « Hide
Issue raised in thread containing:
http://nagoya.apache.org/eyebrowse/ReadMsg?listName=log4cxx-user@logging.apache.org&msgNo=310

Content-Type: text/plain; charset=US-ASCII; format=flowed
From: Curt Arnold <carnold@apache.org>
Subject: LOG4CXX macros
Date: Thu, 12 Aug 2004 11:14:10 -0500


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.

I'd probably implement this by defining a LOG4CXX_UNLIKELY(x) macro
that would be used in LOG4CXX_DEBUG macro. If the compiler did not
support branch hints, then the definition of LOG4CXX_UNLIKELY would be:

#define LOG4CXX_UNLIKELY(x) x

For GCC it would be:

#define LOG4CXX_UNLIKELY(x) __builtin_expect(x, 0)




On Aug 12, 2004, at 10:04 AM, Christophe de VIENNE wrote:

> Curt Arnold wrote:
>
>> Several compilers including gcc have a mechanism to hint that one
>> branch of an if statement is more likely to be executed. It may be
>> desirable that the LOG4CXX_DEBUG hint that isDebugEnabled will likely
>> return false which would allow better optimization for the normal
>> case. Any comments on the benefits or consequences of providing
>> branch hints?
>
> I'm not sure of what you mean by branch hint. Do you have a small and
> concrete example ?
>
>
> Christophe
>





 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.