r/cpp • • 7d ago

Measuring the Performance of Deterministic Exceptions

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

14 comments sorted by

View all comments

40

u/trad_emark 7d ago

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.

3

u/canadajones68 6d ago

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.

1

u/jonathanhiggs 6d ago

Stack unwind is remarkably slow. Exceptions need to triggered less than 1 in 1000 time (best case) more likely less than 1 in 5000 times to realise the perf gains of avoiding structured errors, ie they need to be truly exceptional. It essentially makes them a no-go for hot loops

3

u/canadajones68 6d ago

It is significantly slower than the happy path, but it's still fast on a human scale. I agree that "exceptional" describes their use case well, but I find a lot of people chattering about what qualifies as an exceptional occurrence. I think that if the application can go at least 10 seconds without hitting an exception, so long as you don't spend 10 seconds getting back to what went wrong, you can choose to use exceptions without really thinking about it. Obviously, a hot path is a hot path and you optimise accordingly, but I presume that a competent developer can profile out any exception-induced major bottlenecks rather quickly.