Just eliminated C++ exceptions in a complicated multithreaded library. It’s 15% faster despite all performance sensitive functions previously being declared noexcept, with no obvious explanation.
-
-
And it’s not just C++. Other languages build their exception models on top of C++ exceptions and the operating system level plumbing (why should the OS have anything to do with this?) so, for example, JavaScript exceptions are also impractically expensive.
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
There's a proposal for lighter-weight exceptions in C++. Basically a std::variant return value that either returns what you want or an error... where the compiler converts all that to familiar try/catch semantics. It's a Herb Sutter thing.
-
Of course then there's the whole argument about what an exceptional situation is. Should exceptions just be recoverable, but breaking situations, such as losing internet connection? But then, how should you handle minor errors? Mixed error handling's also bad. Etc. etc.
- 4 more replies
New conversation -
-
-
Ignoring all other downsides of exceptions, "zero-cost" just means that in the case where you don't throw, you don't have a runtime overhead for non-exceptional code branch, which is true. Of course the downside is lots of overhead when actually throwing and catching.
-
I wish it were just normal “lots” like 100 cycles given the need to use a hash table to map the current return address to an exception handler and examine an RTTI type. The 8,000 cycles is inscrutable.
- 1 more reply
New conversation -
-
-
You're right, exceptions should jump to a code section way far away that has all the exception handlers in one place. Like an __attribute__(cold) on steroids. People who (unwisely) use exceptions as control flow wouldn't even notice. The handlers will be hot to them.
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
Unusable is a bit of an exaggeration isn't it? :)
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.