[LLVMdev] OCaml and Exceptions

Gordon Henriksen gordonhenriksen at mac.com
Sun Nov 25 14:52:40 PST 2007


On Nov 25, 2007, at 17:00, Jon Harrop wrote:

> On Sunday 25 November 2007 21:40, Gordon Henriksen wrote:
>
>> 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.

Yes. Not surprising.

>> 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 handlers?

Yes. I should've used the term landing pads (http://llvm.org/docs/ExceptionHandling.html#try_catch 
).

>> 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 were customized?

Likely so. To a reasonable approximation, LLVM EH is C++ EH.

> If so, I don't think that is a problem: exceptions are 600x slower  
> in F# than in OCaml!

:)

— Gordon





More information about the llvm-dev mailing list