Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
June 13, 2004 Why are exceptions so slow? | ||||
---|---|---|---|---|
| ||||
Hi, I don't understand why exceptions are so slow in D. They should be very fast, because, (in my imagination, at least), they don't have to do much. But I just wrote a piece of code yesterday which used pretty much used exceptions like a fancy goto (thanks for that description, guys) and it ran unbelievebly slowly. When I recoded it without exceptions, the speedup was phenomenal. But in my imagination, all you have to do to throw an exception in D is load the stack pointer with a previously stashed value, stash a pointer to the /next/ exception frame down (ready for next time), and perform a jump (through some sort of lookup table based on the type of object thrown). I'm obviously missing something though - it must be doing much more than that or it wouldn't take so long. What am I missing? What else does it have to do? Arcane Jill |
June 13, 2004 Re: Why are exceptions so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Arcane Jill | "Arcane Jill" <Arcane_member@pathlink.com> wrote in message news:cagtdm$1ug5$1@digitaldaemon.com... > Hi, > > I don't understand why exceptions are so slow in D. They should be very fast, > because, (in my imagination, at least), they don't have to do much. But I just > wrote a piece of code yesterday which used pretty much used exceptions like a > fancy goto (thanks for that description, guys) and it ran unbelievebly slowly. > When I recoded it without exceptions, the speedup was phenomenal. > > But in my imagination, all you have to do to throw an exception in D is load the > stack pointer with a previously stashed value, stash a pointer to the /next/ > exception frame down (ready for next time), and perform a jump (through some > sort of lookup table based on the type of object thrown). I'm obviously missing > something though - it must be doing much more than that or it wouldn't take so > long. > > What am I missing? What else does it have to do? It has to be compatible with Microsoft's "Windows Structured Exception Handling" which is far too complicated to explain in a simple post. But it shouldn't matter if it is relatively slow. Exceptions should be for exceptional cases, not the ordinary program flow. |
June 13, 2004 Re: Why are exceptions so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <newshound@digitalmars.com> wrote in message news:cagu40$1vnd$1@digitaldaemon.com... > > "Arcane Jill" <Arcane_member@pathlink.com> wrote in message news:cagtdm$1ug5$1@digitaldaemon.com... > > Hi, > > > > I don't understand why exceptions are so slow in D. They should be very > fast, > > because, (in my imagination, at least), they don't have to do much. But I > just > > wrote a piece of code yesterday which used pretty much used exceptions > like a > > fancy goto (thanks for that description, guys) and it ran unbelievebly > slowly. > > When I recoded it without exceptions, the speedup was phenomenal. > > > > But in my imagination, all you have to do to throw an exception in D is > load the > > stack pointer with a previously stashed value, stash a pointer to the > /next/ > > exception frame down (ready for next time), and perform a jump (through > some > > sort of lookup table based on the type of object thrown). I'm obviously > missing > > something though - it must be doing much more than that or it wouldn't > take so > > long. > > > > What am I missing? What else does it have to do? > > It has to be compatible with Microsoft's "Windows Structured Exception Handling" which is far too complicated to explain in a simple post. You're not wrong, about either the need for SEH compatibility, or its complexity. > But it shouldn't matter if it is relatively slow. Exceptions should be for exceptional cases, not the ordinary program flow. Exactamundo. Theoretically, I concur. Practically, D is not Java, does not have a byte-code interpreter, and therefore must interact with the machine for things like /0 and *NULL. Hence, it is slow. QED -- The Dr. da-da-da-dum, da-da-da-dum, da-da-da-dum, daaah da-da-da-dum, da-da-da-dum, da-da-da-dum, daaah woo-ooooo |
June 13, 2004 Re: Why are exceptions so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | >It has to be compatible with Microsoft's "Windows Structured Exception Handling" which is far too complicated to explain in a simple post. Heres a good article http://www.codetools.com/cpp/exceptionhandler.asp > pretty much used exceptions >like a >> fancy goto Perverse! Charlie In article <cagu40$1vnd$1@digitaldaemon.com>, Walter says... > > >"Arcane Jill" <Arcane_member@pathlink.com> wrote in message news:cagtdm$1ug5$1@digitaldaemon.com... >> Hi, >> >> I don't understand why exceptions are so slow in D. They should be very >fast, >> because, (in my imagination, at least), they don't have to do much. But I >just >> wrote a piece of code yesterday which used pretty much used exceptions >like a >> fancy goto (thanks for that description, guys) and it ran unbelievebly >slowly. >> When I recoded it without exceptions, the speedup was phenomenal. >> >> But in my imagination, all you have to do to throw an exception in D is >load the >> stack pointer with a previously stashed value, stash a pointer to the >/next/ >> exception frame down (ready for next time), and perform a jump (through >some >> sort of lookup table based on the type of object thrown). I'm obviously >missing >> something though - it must be doing much more than that or it wouldn't >take so >> long. >> >> What am I missing? What else does it have to do? > >It has to be compatible with Microsoft's "Windows Structured Exception Handling" which is far too complicated to explain in a simple post. > >But it shouldn't matter if it is relatively slow. Exceptions should be for exceptional cases, not the ordinary program flow. > > |
June 13, 2004 Re: Why are exceptions so slow? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Charlie | "Charlie" <Charlie_member@pathlink.com> wrote in message news:cahflb$2onn$1@digitaldaemon.com... > >It has to be compatible with Microsoft's "Windows Structured Exception Handling" which is far too complicated to explain in a simple post. > > Heres a good article http://www.codetools.com/cpp/exceptionhandler.asp That's a good introduction to SEH, thanks. |
Copyright © 1999-2021 by the D Language Foundation