[LLVMdev] OCaml and Exceptions

Eric Christopher echristo at apple.com
Sun Nov 25 14:16:31 PST 2007


On Nov 25, 2007, at 2:00 PM, Jon Harrop wrote:

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

The idea behind the implementation of C++ exceptions is that C++  
exceptions
handle "exceptional" conditions, not normal code path. I.e. If you're  
throwing an
exception in the course of normal execution, there's something wrong  
with your
code. This means that C++ exceptions handle the normal case very well  
(no
overhead), but that the exceptional condition is OK with being slower  
as a tradeoff.

That said, I don't know much about OCaml and so don't know if this  
philosophy
fits the standard OCaml programming style. If throw/catch/etc are  
meant to be
normal path of execution then a small cost up front in, for example,  
try blocks
could easily speed up execution later when you hit the throw.

-eric



More information about the llvm-dev mailing list