Re: How expensive are exceptions?
Andrei Alexandrescu (See Website For Email) wrote:
David Abrahams wrote:
The "zero-cost" refers to the cost of EH when no exceptions are
thrown, not the cost of actually unwinding. Almost nobody bothers to
optimize that.
It was about the successful paths. The article analyzed the cost of the
successful paths in try/catch code, and concluded that even in the
zero-cost implementations, the generated code suffered of a performance
loss compared to the if/else version.
I didn't see the article, but at least on Windows, having EH enabled
does add some cost to successful paths. The reason is because EH on x86
Windows is implemented using Microsoft's "Structured Exception Handling"
scheme which requires:
1) a special stack frame
2) incrementing/decrementing a special 'scope index' variable when going
in and out of try blocks
I think this cost was reduced for SEH on x64, at the cost of much slower
execution of catch blocks. While the modern trend is to accept slow
exception paths, such does preclude using the hardware to implement
write barriers in gc implementations.
--------------
Walter Bright
http://www.digitalmars.com C, C++, D programming language compilers
http://www.astoriaseminar.com Extraordinary C++
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]