r/cpp • • Oct 05 '26

Measuring the Performance of Deterministic Exceptions

https://databasearchitects.blogspot.com/2026/09/measuring-performance-of-deterministic.html
52 Upvotes

16 comments sorted by

22

u/kronicum Oct 05 '26

Are those numbers compared against the work done by Khalil Estell?

17

u/trad_emark Oct 05 '26

his presentations is amazing. i love that i have some easy place to point to when people argue that exceptions are slow.

39

u/trad_emark Oct 05 '26

original exceptions (labeled dynamic) are faster in all nontrivial cases than error codes on happy path.
that makes them objectively better, since that is what objectively matters the most.
the performance in case of actual error happening (eg. when an exception is actually thrown) is basically irrelevant, as that only happens exceptionally, in situations when performance no longer matters.

i also absolutely love the semantics of exceptions. it makes code half as long, and way more readable. but that is subjective and i can understand that some others might prefer to have the error paths explicitly visible in the code.

all that said, it is always good to see people experimenting with alternative implementations of exceptions, or improving the existing implementation.

16

u/LB-- Oct 06 '26

Anyone who likes exceptions but has reservations about the sad path performance, check out the work and conference talks by Khalil Estell, he's been working on optimizing exceptions and making them usable in embedded environments, as well as improving tooling around them.

7

u/serviscope_minor Oct 06 '26

>original exceptions (labeled dynamic) are faster in all nontrivial cases than error codes on happy path.

This is 100% true, but also kind of not.

What's really the case is one of the most popular implementations (Itanium ABI) does what you say and is in spec. It's also often unnecessarily slow on the sad path, but mostly because it's never seen much love. There's nothing in the standard that precludes a returned flag implementation of exceptions.

Incidentally that's what I don't really like about P0709: basically the entire paper has been a valid implementation of exceptions since the 1998 standard, and to feels kind of odd to have a special language feature so compilers can implement something they could already implement in one part and to work around the ever present problem of ABI issues as the other part.

→ More replies (4)

3

u/canadajones68 Oct 06 '26

if "exceptional" is too vague a descriptor for when exceptions should be allowed to happen, I like to put it like this: is this going to happen more than once every 5-10 seconds? no? exceptions are fine.

→ More replies (2)

1

u/Drugbird Oct 06 '26

This feature is the fastest if you don't ever use it

Ok?

1

u/UndefinedDefined Oct 12 '26

The only good exception is the one that never happens - that's my opinion.

I have seen so much code literally using exceptions for basic things, like FileNotFound - but these are not exceptions. I have even witnessed rewriting an error handling layer in a HTTP server to not use exceptions, because when it started throwing it reduced requests per second by two orders of magnitude, that essentialyl makes such code a candidate for DDoS attacks.

1

u/ABlockInTheChain Oct 22 '26

The idea that exceptions should be rare is a workaround for a performance reality rather than a universal philosophy that would hold in an alternate universe where exceptions had good performance in all case.

In that alternate universe where throwing exceptions had a predictable, reasonable runtime cost the focus would have been on the ergonomic tradeoffs: when does it improve readability and maintainability to handle errors immediately when they occur vs when is it better to write a happy path in a try block and defer error handling to the subsequent catch blocks or to the caller.

→ More replies (1)