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.
-
Show this thread
-
Exception throwing on Windows x64 is 8,000 CPU cycles in Visual C++ and 20,000 in clang, but grows to 1,800,000 when a debugger is attached to the process.
4 replies 19 retweets 144 likesShow this thread -
This cost is mind-boggling for what is essentially a goto-with-destructors. In the process of adopting the “zero cost exceptions” fallacy, modern platforms created a catastrophic performance cliff that makes the feature unusable in real software.
5 replies 8 retweets 188 likesShow this thread -
Replying to @TimSweeneyEpic
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.
1 reply 0 retweets 3 likes -
Replying to @scottmichaud @TimSweeneyEpic
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.
2 replies 0 retweets 0 likes -
Replying to @scottmichaud
Exceptions should be a normal control flow mechanism. It’s perfectly reasonable to want to non-locally exit a series of nested function calls, for example so a parser can backtrack to the next alternative via exception rather than indicating failure via convoluted return types.
3 replies 0 retweets 8 likes -
Replying to @TimSweeneyEpic @scottmichaud
Multi return value... But that's not c++.
2 replies 0 retweets 1 like -
Replying to @YvanDaSilva @TimSweeneyEpic
Could return a std::variant for multiple return values. That's basically the core of Herb Sutter proposal. The main thing is having a clean way to handle them in "branch all the way out of here right this very instant" situations. That's where some compiler magic would be nice.
1 reply 0 retweets 0 likes
Compiler Magic is needed to ensure that return value optimization and copy elision work despite the possibility of exceptions. Ultimately, this is the key reason we need exceptions and not just return fancy templated types.
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.