[LLVMdev] OCaml and Exceptions
jon at ffconsultancy.com
Sun Nov 25 14:00:27 PST 2007
On Sunday 25 November 2007 21:40, Gordon Henriksen wrote:
> On Nov 25, 2007, at 11:49, Jon Harrop wrote:
> > So does zero-cost exception handling in C++ refer to a special case
> > where you can statically prove that there are no destructors to
> > call, or something?
> "Zero cost" refers to the overhead introduced in the case when an
> exception is not thrown at all.
Ah, I see.
> > There is one thing that confuses me about this though. I benchmarked
> > exception handling in OCaml and C++ a while ago and found OCaml to
> > be ~6x faster and the best explanation I got was that C++ does not
> > have zero-cost exceptions
> Microbenchmarking raise vs. throw is not very realistic...
Just to clarify: the benchmark compared the performance of RB tree
implementations using exceptions to terminate early when an already-present
element was inserted. I found that it is more efficient in C++ (using g++) to
mimic the exception using nested "if"s rather than throw and catch. Although
simple, this benchmark was of practical importance to me at the time.
> GC in general will reduce the amount of cleanup code, which should
> reduce DWARF EH's actual overhead (fewer cleanup blocks means smaller
> tables and accordingly cheaper unwinds), especially when unwinding
> deep stacks.
I'm not quite sure I understand this (I don't even know what DWARF EH is!) but
are "cleanup blocks" the construct that I would be using to build exception
> Objective-C 2 on Leopard may be one of the few systems
> which has this combination of properties. (But exceptions in Cocoa
> code are discouraged even more strongly than in C++.)
> Note that there is nothing in LLVM that prevents alternative exception
> handling regimes, they just won't benefit from the existing
> infrastructure, and will not interoperate with the DWARF runtime.
Ok. Might as well start by reusing as much as possible. Exceptions are very
common in OCaml though. Is my 6x result a fair quantitative estimate of how
much faster exceptions could be make in this system for my compiler if it
If so, I don't think that is a problem: exceptions are 600x slower in F# than
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
More information about the llvm-dev