The hidden cost of exception handling

I've just published a blog article about the hidden cost of exception handling that may interest some of the readers here.

During a meeting today, a colleague of mine shared the belief that exception handling had no impact on optimizations in modern C++. While we did everything we could 20+ years ago to ensure that all kinds of optimizations were possible, there is a residual cost that you can trigger.

In this post, I show cases where there is zero cost for exception handling in the primary execution path, but also build a few pathological cases where the compiler cannot preserve that property, and where just enabling exceptions markedly changes the primary code path, for reasons that may be related more to correctness than to optimizations, in other words, where it may not ever be possible to fully optimize without violating C++ semantics.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Nice write-up!

Finally had some time to work through your article.

Well done!

Although the article is fairly specific to the curse that is C++, the fundamental challenges seem to apply universally.