digitalmars.D - Why are exceptions so slow?
- Arcane Jill (14/14) Jun 12 2004 Hi,
- Walter (15/28) Jun 13 2004 fast,
- The Dr ... who? (11/42) Jun 13 2004 You're not wrong, about either the need for SEH compatibility, or its co...
- Charlie (4/40) Jun 13 2004 Perverse!
- Walter (3/6) Jun 13 2004 That's a good introduction to SEH, thanks.
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
Jun 12 2004
"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 veryfast,because, (in my imagination, at least), they don't have to do much. But Ijustwrote a piece of code yesterday which used pretty much used exceptionslike afancy goto (thanks for that description, guys) and it ran unbelieveblyslowly.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 isload thestack pointer with a previously stashed value, stash a pointer to the/next/exception frame down (ready for next time), and perform a jump (throughsomesort of lookup table based on the type of object thrown). I'm obviouslymissingsomething though - it must be doing much more than that or it wouldn'ttake solong. 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.
Jun 13 2004
"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...You're not wrong, about either the need for SEH compatibility, or its complexity.Hi, I don't understand why exceptions are so slow in D. They should be veryfast,because, (in my imagination, at least), they don't have to do much. But Ijustwrote a piece of code yesterday which used pretty much used exceptionslike afancy goto (thanks for that description, guys) and it ran unbelieveblyslowly.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 isload thestack pointer with a previously stashed value, stash a pointer to the/next/exception frame down (ready for next time), and perform a jump (throughsomesort of lookup table based on the type of object thrown). I'm obviouslymissingsomething though - it must be doing much more than that or it wouldn'ttake solong. 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.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
Jun 13 2004
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.asppretty much used exceptions like aPerverse! Charlie In article <cagu40$1vnd$1 digitaldaemon.com>, Walter says...fancy goto"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 veryfast,because, (in my imagination, at least), they don't have to do much. But Ijustwrote a piece of code yesterday which used pretty much used exceptionslike afancy goto (thanks for that description, guys) and it ran unbelieveblyslowly.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 isload thestack pointer with a previously stashed value, stash a pointer to the/next/exception frame down (ready for next time), and perform a jump (throughsomesort of lookup table based on the type of object thrown). I'm obviouslymissingsomething though - it must be doing much more than that or it wouldn'ttake solong. 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.
Jun 13 2004
"Charlie" <Charlie_member pathlink.com> wrote in message news:cahflb$2onn$1 digitaldaemon.com...That's a good introduction to SEH, thanks.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
Jun 13 2004