3 ms·
Exceptions have zero cost when not thrown, apart from being included in the binary
by alphanullmeric 4y ago
Exceptions have zero cost when not thrown, apart from being included in the binary
- pornel 4y agoA mere possibility of a function throwing an exception is a side effect that an optimiser can't ignore, and this inhibits many types of optimisations involving code motion. This is for example the main cost of bound checking in Rust, not the branches.
- AshamedCaptain 4y agoI always hear this, but these days entire Linux distros build with -fasynchronous-unwind-tables which has much more overhead than C++ exceptions, since now you have to provide an unwind path for every single instruction boundary. Even Chrome does it (for "accurate stack traces") when otherwise they're on the no exceptions camp. Using this option also completely subsumes the otherwise negligible cost of C++ exceptions, which only affects non-inlined function calls (which already limit code motion anyway).