Does D use zero-cost exceptions?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Tue Apr 16 21:46:51 UTC 2019


On 4/16/19 4:52 PM, Steven Schveighoffer wrote:
> On 4/15/19 4:24 PM, Andrei Alexandrescu wrote:
>> On 4/15/19 3:36 PM, Nicholas Wilson wrote:
>>> On Monday, 15 April 2019 at 19:25:24 UTC, A wrote:
>>>> It is well known that exceptions are much slower than their 
>>>> alternatives, but is there a performance cost for using try/catch, 
>>>> even when no Exception/Error is being thrown?
>>>
>>> There is a space cost for the unwind tables, but exceptions are 
>>> faster than checking error codes all over the place (you do check 
>>> them right? ;) ).
>>
>> Sadly that's not quite the case... we've run a bunch of test at 
>> Facebook back in the day and the sheer presence of unwinding disables 
>> a bunch of optimizations, notably code motion and everything enabled 
>> by it. The bottom line effect is quite unpleasant, in the single digits.
> 
> It would be important to know what "the day" was. Because there have 
> been a lot of improvements on LLVM. I wonder if some of this has been 
> mitigated for LDC at least.

2015. I'll ask for an update.

>> This is a problem important enough for C++ that they added a keyword 
>> dedicated to it (noexcept).
> 
> Don't we have nothrow for this?

We do, but... see Walter's explanation.


More information about the Digitalmars-d mailing list