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
On Sunday 25 November 2007 22:16, Eric Christopher wrote:> 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.Exceptions are often raised and caught in OCaml programs so an optimizing OCaml compiler would be expected to provide very fast throwing and catching of exceptions. However, optimizing them now when we already have an easy to use exception mechanism would be premature: I'd like to get something useful up and running first and leave these kinds of optimizations. -- Dr Jon D Harrop, Flying Frog Consultancy Ltd. http://www.ffconsultancy.com/products/?e
On Nov 25, 2007 5:23 PM, Jon Harrop <jon at ffconsultancy.com> wrote:> On Sunday 25 November 2007 22:16, Eric Christopher wrote: > > 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. > > Exceptions are often raised and caught in OCaml programs so an optimizing > OCaml compiler would be expected to provide very fast throwing and catching > of exceptions. > > However, optimizing them now when we already have an easy to use exception > mechanism would be premature: I'd like to get something useful up and running > first and leave these kinds of optimizations.Exception handling can be naively handled via closures, so the amortized cost is an indirect function call. This requires some program transformation where try-catch expressions are lifted into their own functions and passed to callers. What does OCaml actually do in this case? Sandro