4 ms·
From Joe Duffy's series of blog posts on Midori[1]: > Error codes fail the test of “zero overhead for common cases; pay for play for uncommon cases”: > There
by Mindless2112 6y ago
From Joe Duffy's series of blog posts on Midori[1]:
> Error codes fail the test of “zero overhead for common cases; pay for play for uncommon cases”:
> There is calling convention impact. You now have two values to return (for non-void returning functions): the actual return value and the possible error. This burns more registers and/or stack space, making calls less efficient. Inlining can of course help to recover this for the subset of calls that can be inlined.
> There are branches injected into callsites anywhere a callee can fail. I call costs like this “peanut butter,” because the checks are smeared across the code, making it difficult to measure the impact directly. In Midori we were able to experiment and measure, and confirm that yes, indeed, the cost here is nontrivial. There is also a secondary effect which is, because functions contain more branches, there is more risk of confusing the optimizer.
> This might be surprising to some people, since undoubtedly everyone has heard that “exceptions are slow.” It turns out that they don’t have to be. And, when done right, they get error handling code and data off hot paths which increases I-cache and TLB performance, compared to the overheads above, which obviously decreases them.
[1] http://joeduffyblog.com/2016/02/07/the-error-model/ http://joeduffyblog.com/2016/02/07/the-error-model/
- ncmncm 6y agoNobody seems to mention this when comparing, but code to handle the case of getting a bad error code is almost always very poorly exercised: therefore, buggy. That is in contrast to the code run during an exception, the destructors, which run all the damn time. If you do make the effort to test your error-handling code, that is a significant expense on top of the reduced performance. Maintaining those tests as the code changes from under them is another expense.
- p0nce 6y agoExactly this. It's hardly ever mentionned, but as error paths are less tested, code that is written without exceptions (and RAII) will be wrong a lot more often.
- CodesInChaos 6y agoDestructors/RAII and finally statements work just as well when returning error codes as they do with exceptions.