David Stone: Exceptional Performance
Channel: CppNow
Date: 2016-07-14

When many of us choose C++, performance is one of the most important factors. It is so ingrained in the culture of C++ that the single most important tenant of C++ is probably "You don't pay for what you don't use". This shows up in almost all components of modern C++: zero-cost abstractions backed by a powerful optimizing compiler. Yet there is one component of the language that appears to violate this rule: exceptions. The mere possibility of exceptions can force the compiler to generate different, slower, code than it otherwise would have. Throwing an exception is a slow operation, and exceptions can lead to an increase in code size. There is a lot of conflicting advice on what exactly the programmer can do to make sure that they only pay for what they use that runs the gamut from "Don't worry about it" to "Pass this special flag to your compiler to turn off exceptions". The situation is only made more complicated by the introduction of the noexcept keyword. In this presentation, we will discuss exactly what effect exceptions have on the performance of an application, backed up by numbers from both benchmarks and real world applications. We will go into the details of hardware architecture and memory hierarchy to try to understand exactly why code performs the way it does. Could it ever make sense to say that you using exceptions for performance reasons?
---

*--*

---