Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is an interesting source of "death-of-a-thousand-cuts" performance problems in C++ codebases, as well. Code you never even execute can slow you down; stack-unwinding code for unhandled exceptions takes up precious icache bytes between the bodies of useful functions. Good luck finding this with a profiler; every function executes epsilon slower, since a cache miss is that much more likely to fetch its body.


The stack unwinder should be a separate function altogether, not interspersed with your code.

Activation record cleanup, on the other hand, will be inside your routines, and will be executed both in cases of normal and abnormal exit. But this isn't the responsibility of exceptions; you have to do this cleanup even on normal exit.

Code that runs only in exceptional cases is comparatively rare. But with exceptions, you can move that code somewhere else entirely; and with PC-based exception handling, the space cost is only borne when an exception is thrown, when the PC lookup tables need to be paged in. In this scenario, the tradeoff between exceptions and error codes becomes relevant: exceptions let your code get smaller at the cost of a hit when an exception is actually thrown, while error codes bloat your code.

Of course, all of the above is not specific to C++. C++ has other deficiencies which can lead to suboptimal pathologies in practice.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: