4 ms·
I think in practice it isn't a higher cost: a lot of code in languages with nullable pointers also has a pile of unnecessary dynamic checks (e.g. checking argum
by dbaupp 9y ago
I think in practice it isn't a higher cost: a lot of code in languages with nullable pointers also has a pile of unnecessary dynamic checks (e.g. checking arguments aren't null).
- qznc 9y agoExceptions (implemented zero-cost style) are truly zero cost. No dynamic checks as long as no exception is thrown.
- lmm 9y agoExceptions aren't zero-cost either: they require you to be able to unwind the stack, so you have to keep the frame pointer and have one fewer general-purpose register to work with.
- cwzwarich 9y agoYou actually don't need the frame pointer to unwind the stack. DWARF frame info allows the compiler to specify tables that describe the stack layout at every program point, and this can be used to perform unwinding. Another reason why exceptions aren't zero-cost in practice is that compilers need to model the exceptional control-flow, and they usualy don't do a great job in this situation and miss a lot of potential optimizations.
- dbaupp 9y agoThe cost being compared here is the 'if x.is_none()' or 'if x == null' check, not what happens after it.