digitalmars.D - Does D use zero-cost exceptions?
- A (3/3) Apr 15 2019 It is well known that exceptions are much slower than their
- Nicholas Wilson (6/9) Apr 15 2019 There is a space cost for the unwind tables, but exceptions are
- Andrei Alexandrescu (7/15) Apr 15 2019 Sadly that's not quite the case... we've run a bunch of test at Facebook...
- Russel Winder (18/21) Apr 16 2019 On Mon, 2019-04-15 at 16:24 -0400, Andrei Alexandrescu via Digitalmars-
- Araq (6/13) Apr 16 2019 Did you compare it to if-based error handling or to calling
- Steven Schveighoffer (6/22) Apr 16 2019 It would be important to know what "the day" was. Because there have
- Walter Bright (5/6) Apr 16 2019 Yes.
- Andrei Alexandrescu (3/26) Apr 16 2019 We do, but... see Walter's explanation.
- Andrei Alexandrescu (8/30) Apr 21 2019 OP delivers... got this: "RAII code introduces unwind code which can
- Mike Franklin (18/21) Apr 15 2019 I haven't benchmarked D, but I did do some benchmarking with C++
- Radu (5/8) Apr 15 2019 You can check this by looking at the generated assembly.
- matheus (4/7) Apr 29 2019 Herb Sutter ACCU presentation about this Exception Handling x
It is well known that exceptions are much slower than their alternatives, but is there a performance cost for using try/catch, even when no Exception/Error is being thrown?
Apr 15 2019
On Monday, 15 April 2019 at 19:25:24 UTC, A wrote:It is well known that exceptions are much slower than their alternatives, but is there a performance cost for using try/catch, even when no Exception/Error is being thrown?There is a space cost for the unwind tables, but exceptions are faster than checking error codes all over the place (you do check them right? ;) ). If an error is thrown you application is dead (or UB) anyway. Please use the learn forum for such questions in the future.
Apr 15 2019
On 4/15/19 3:36 PM, Nicholas Wilson wrote:On Monday, 15 April 2019 at 19:25:24 UTC, A wrote:Sadly that's not quite the case... we've run a bunch of test at Facebook back in the day and the sheer presence of unwinding disables a bunch of optimizations, notably code motion and everything enabled by it. The bottom line effect is quite unpleasant, in the single digits. This is a problem important enough for C++ that they added a keyword dedicated to it (noexcept).It is well known that exceptions are much slower than their alternatives, but is there a performance cost for using try/catch, even when no Exception/Error is being thrown?There is a space cost for the unwind tables, but exceptions are faster than checking error codes all over the place (you do check them right? ;) ).
Apr 15 2019
On Mon, 2019-04-15 at 16:24 -0400, Andrei Alexandrescu via Digitalmars- d wrote: [=E2=80=A6]=20 This is a problem important enough for C++ that they added a keyword=20 dedicated to it (noexcept).Herb Sutter has a proposal for exception handling in C++ to make it better. His keynote at ACCU 2019 is reputedly the first public presentation. Slides are at: https://github.com/ACCUConf/PDFs_2019/blob/master/herb_sutter_-_de-fragment= ing_cpp__making_exceptions_more_affordable_and_usable.pdf video will be up on YouTube as soon as the videographers can put things up. (There has been an issue outwith the videographers' control that has meant things are not going up within 24 hours of being recorded.) --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk
Apr 16 2019
On Monday, 15 April 2019 at 20:24:27 UTC, Andrei Alexandrescu wrote:Sadly that's not quite the case... we've run a bunch of test at Facebook back in the day and the sheer presence of unwinding disables a bunch of optimizations, notably code motion and everything enabled by it. The bottom line effect is quite unpleasant, in the single digits. This is a problem important enough for C++ that they added a keyword dedicated to it (noexcept).Did you compare it to if-based error handling or to calling terminate/abort on error? I would expect that excessive if statements for error handling prevent the code motion optimizations in the same way.
Apr 16 2019
On 4/15/19 4:24 PM, Andrei Alexandrescu wrote:On 4/15/19 3:36 PM, Nicholas Wilson wrote:It would be important to know what "the day" was. Because there have been a lot of improvements on LLVM. I wonder if some of this has been mitigated for LDC at least.On Monday, 15 April 2019 at 19:25:24 UTC, A wrote:Sadly that's not quite the case... we've run a bunch of test at Facebook back in the day and the sheer presence of unwinding disables a bunch of optimizations, notably code motion and everything enabled by it. The bottom line effect is quite unpleasant, in the single digits.It is well known that exceptions are much slower than their alternatives, but is there a performance cost for using try/catch, even when no Exception/Error is being thrown?There is a space cost for the unwind tables, but exceptions are faster than checking error codes all over the place (you do check them right? ;) ).This is a problem important enough for C++ that they added a keyword dedicated to it (noexcept).Don't we have nothrow for this? -Steve
Apr 16 2019
On 4/16/2019 1:52 PM, Steven Schveighoffer wrote:Don't we have nothrow for this?Yes. The problem with EH is not in the throwing, it's in the unwinding. Each RAII object requires its own try-finally, and try-finally disables many optimizations (such as code motion, enregistering of variables, etc.).
Apr 16 2019
On 4/16/19 4:52 PM, Steven Schveighoffer wrote:On 4/15/19 4:24 PM, Andrei Alexandrescu wrote:2015. I'll ask for an update.On 4/15/19 3:36 PM, Nicholas Wilson wrote:It would be important to know what "the day" was. Because there have been a lot of improvements on LLVM. I wonder if some of this has been mitigated for LDC at least.On Monday, 15 April 2019 at 19:25:24 UTC, A wrote:Sadly that's not quite the case... we've run a bunch of test at Facebook back in the day and the sheer presence of unwinding disables a bunch of optimizations, notably code motion and everything enabled by it. The bottom line effect is quite unpleasant, in the single digits.It is well known that exceptions are much slower than their alternatives, but is there a performance cost for using try/catch, even when no Exception/Error is being thrown?There is a space cost for the unwind tables, but exceptions are faster than checking error codes all over the place (you do check them right? ;) ).We do, but... see Walter's explanation.This is a problem important enough for C++ that they added a keyword dedicated to it (noexcept).Don't we have nothrow for this?
Apr 16 2019
On 4/16/19 5:46 PM, Andrei Alexandrescu wrote:On 4/16/19 4:52 PM, Steven Schveighoffer wrote:OP delivers... got this: "RAII code introduces unwind code which can constrain optimizations and keep more values alive after a callsite (that can throw) but it’s possible to annotate noexcept functions, and LTO can do that too (I mean probably, I didn’t actually check). LTO, autoFDO, and hot/code layout have been getting better in gcc and clang, plus tools like bolt can move cold unwind code bloat to cold pages and reduce TLB misses in hot functions that have unwinding."On 4/15/19 4:24 PM, Andrei Alexandrescu wrote:2015. I'll ask for an update.On 4/15/19 3:36 PM, Nicholas Wilson wrote:It would be important to know what "the day" was. Because there have been a lot of improvements on LLVM. I wonder if some of this has been mitigated for LDC at least.On Monday, 15 April 2019 at 19:25:24 UTC, A wrote:Sadly that's not quite the case... we've run a bunch of test at Facebook back in the day and the sheer presence of unwinding disables a bunch of optimizations, notably code motion and everything enabled by it. The bottom line effect is quite unpleasant, in the single digits.It is well known that exceptions are much slower than their alternatives, but is there a performance cost for using try/catch, even when no Exception/Error is being thrown?There is a space cost for the unwind tables, but exceptions are faster than checking error codes all over the place (you do check them right? ;) ).
Apr 21 2019
On Monday, 15 April 2019 at 19:25:24 UTC, A wrote:It is well known that exceptions are much slower than their alternatives, but is there a performance cost for using try/catch, even when no Exception/Error is being thrown?I haven't benchmarked D, but I did do some benchmarking with C++ (arm-none-eabi-g++) on an ARM Cortex-M embedded application. What I found was that, compared with checking error codes every step of the way, exceptions slightly improved runtime performance when no exception was thrown. However, once an exception was thrown, the performance cost was heavy. For that application, I opted for using exceptions only where the condition causing an exception to be thrown was an unrecoverable failure and the system had to be gracefully shut down. At that point all bets were off anyway and it was just about logging the failure for investigators. I don't know how that translates to D. I suggest running some benchmarks yourself. It would probably be an interesting topic for many, so you could even make a blog post out of it, help others understand the issue more deeply, and get a little notoriety for your work. Mike
Apr 15 2019
On Monday, 15 April 2019 at 19:25:24 UTC, A wrote:It is well known that exceptions are much slower than their alternatives, but is there a performance cost for using try/catch, even when no Exception/Error is being thrown?You can check this by looking at the generated assembly. I tried this https://godbolt.org/z/fl8qlv and looks that for non-exception path there is no cost associated with it, at least for LDC.
Apr 15 2019
On Monday, 15 April 2019 at 19:25:24 UTC, A wrote:It is well known that exceptions are much slower than their alternatives, but is there a performance cost for using try/catch, even when no Exception/Error is being thrown?Herb Sutter ACCU presentation about this Exception Handling x Zero-Overhead: https://youtu.be/os7cqJ5qlzo?t=860 Matheus.
Apr 29 2019