Does D use zero-cost exceptions?

Mike Franklin slavo5150 at yahoo.com
Tue Apr 16 00:40:53 UTC 2019


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?

I haven't benchmarked D, but I did do some benchmarking with C++ 
(arm-none-eabi-g++) on an ARM Cortex-M embedded application.  
What I found was that, compared with checking error codes every 
step of the way, exceptions slightly improved runtime performance 
when no exception was thrown.  However, once an exception was 
thrown, the performance cost was heavy.

For that application, I opted for using exceptions only where the 
condition causing an exception to be thrown was an unrecoverable 
failure and the system had to be gracefully shut down. At that 
point all bets were off anyway and it was just about logging the 
failure for investigators.

I don't know how that translates to D.  I suggest running some 
benchmarks yourself.  It would probably be an interesting topic 
for many, so you could even make a blog post out of it, help 
others understand the issue more deeply, and get a little 
notoriety for your work.

Mike


More information about the Digitalmars-d mailing list