How fast is D compared to C++?

Walter Bright newshound2 at digitalmars.com
Wed Mar 2 13:20:44 PST 2011


dsimcha wrote:
> == Quote from Walter Bright (newshound2 at digitalmars.com)'s article
>> bearophile wrote:
>>> Bekenn:
>>>
>>>> The use of ref introduces a level of indirection.
>>> This is correct. But a minimally decent compiler must be able to remove this
>>> indirection where possible, like here, and produce efficient code.
>> Having the optimizer remove indirection is rarely possible in C or C++, due to
>> aliasing.
> 
> I'm sure there are tons of nitty-gritty details in implementing something like
> this properly, but **in principle**, can't the compiler put a runtime check in for
> aliasing and select the code path based on whether aliasing is present or not?
> Essentially, you'd have two generated functions, one that handles the aliasing
> case and one that handles the no-aliasing case.

The check will cost you more than you win!

But even a check is rarely even possible. Call any function in C/C++, and the 
optimizer has to throw in the towel on the values of any indirect references. 
Even if the optimizer can do interprocedural analysis, the source of that 
function may not be available to the compiler, or the function may be a virtual 
call.

D has a number of characteristics which can permit much more aggressive 
optimization, but the opportunity is unrealized.


More information about the Digitalmars-d mailing list