gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Gnustep-cvs] r27578 - in /libs/base/trunk: ./ SSL/ Source/ Source/A


From: David Chisnall
Subject: Re: [Gnustep-cvs] r27578 - in /libs/base/trunk: ./ SSL/ Source/ Source/Additions/ Tools/
Date: Mon, 12 Jan 2009 14:40:26 +0000

On 12 Jan 2009, at 14:30, Fred Kiefer wrote:

The ASSGIN macro is different,
that one is valuable in itself

Has anyone actually run a benchmark on the current ASSIGN() macro? It contains three conditionals, in the current implementation. The first one is very rare, and the second two are quite rare.

On any modern CPU, conditional branches are very expensive, and we are incurring this cost in all cases. We are also bloating up the code size, which has an additional effect on the instruction cache usage. The following implementation will be much faster in the common cases:

#define ASSIGN(object, value) do {\
        id __value = [value retain];\
        [object release]; \
        object = __value;\
} while(0);

The message lookup function tests if object and value are nil, so in most cases we are performing this test twice. Since the lookup function is not visible to the compiler, these can not be optimised away, and so we need to do the same test twice in two bits of code.

The test whether value == object is even more rare, and the cost of the extra conditional here is likely to be vastly more than the saving from sending two messages in the rare case where it does occur.

David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]