3 ms·
C++ exceptions have a lot of machinery behind the scenes, and I don’t think anybody has ever really put the effort in to optimize pathological edge cases like t
by vgatherps 4y ago
C++ exceptions have a lot of machinery behind the scenes, and I don’t think anybody has ever really put the effort in to optimize pathological edge cases like this.
- int_19h 4y agoA lot of time and effort went into optimizing the most common case (no exceptions - ideally this should be no-cost) at the expense of everything else. It's very much by design.
- vgatherps 4y agoYes, 100%! This is exactly the machinery the makes it hard for a compiler to elide the exception. I don’t think there’s anything in the standard that prevents the compiler from optimizing away said exception completely, but neither gcc or clang do so even in extremely trivial cases where the exception is identical to an if statement: https://godbolt.org/z/8Y81bzo5s https://godbolt.org/z/8Y81bzo5s