Re:Ask HN: Big C++ projects that uses Exceptions and RTTI?
by kwant_kiddo on Saturday November 25, 2023 @03:04PM
(#38416217)
The premise is that exceptions should be zero cost to check, however it worries me when profiles like Tim Sweeney says that his code got 15% faster by turning off exceptions [1].
[1]: https://twitter.com/TimSweeneyEpic/status/122307740466037145...
Don’t get me wrong, maintaining exception guarantees and ensuring exceptions are appropriately caught is terrible. I much prefer working with optional and outcome and similar personally, but the assumption of exceptions is very deeply baked in, and avoiding them safely is a lot harder than one might guess.
Also, remember that while exceptions cost code size, they cost literally nothing in instructions executed unless an exception is actually thrown. That’s why the common nix implementation is called “zero cost exceptions”. In the happy path case they are faster than returning a discriminant. It’s not having exceptions available that makes code slow, it’s using them for things that are expected rather than unexpected or for control flow.