Re:Size cost of C++ exception handling on embedded platforms
by curryhoward on Monday May 16, 2016 @05:27AM
(#11705211)
True, and a good type system will enforce that you check for errors. However, depending on how often errors occur in your program, this can actually make your code slower. Good exception handling implementations are "zero-cost", meaning that there is no performance impact in the happy path (when no exceptions are raised). C-style error handling (an if statement) is actually slower, at least in non-embedded environments.
[ Parent
| on HN ]
Re:Size cost of C++ exception handling on embedded platforms
by haldean on Monday May 16, 2016 @12:43PM
(#11707552)
In C, there are ways you can get the optimizer to turn if-based error handling into something that only spends one or two instructions; using __builtin_expect[0] can decrease the cost of a condition by letting the branch predictor pick the "right" thing to expect. That way you end up only paying the price of the branch (and maybe the jump) instructions without any pipeline flushes or stalls.
[0]: http://blog.man7.org/2012/10/how-much-do-builtinexpect-likel...