Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[ANN] Js_of_ocaml version 1.0
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-12-13 (15:45)
From: Jerome Vouillon <Jerome.Vouillon@p...>
Subject: Re: [Caml-list] [ANN] Js_of_ocaml version 1.0
On Mon, Dec 13, 2010 at 09:58:27AM -0500, Yitzhak Mandelbaum wrote:
> One small question: could you expand on your last comment:
> On Dec 13, 2010, at 8:06 AM, Jerome Vouillon wrote:
> > <snip>
> > 
> > Ocamljs optimizes tail recursion, but this comes at a large
> > performance cost.
> Do you mean all tail-calls come a large cost, or only those outside
> of plain tail-recursion?  Either way, could you give us some more
> intuition as to why this happens, and why js_of_ocaml doesn't suffer
> from the same problem (assuming it applies to tail-recursion)?

I meant tail calls, indeed.  Tail recursion (when a function calls
itself recursively in tail position) can be optimized efficiently by
wrapping the function body inside a loop.  This is what Js_of_ocaml

For optimizing tail calls in general, you need to use trampolines.
Instead of calling a function in tail position, you return this
function and its arguments.  Then, a piece of code called a trampoline
takes care of invoking repeately the functions it receives this way
until a final result is returned.  This is expansive.  You have to
make sure that this piece of code is there whenever a function is
invoked in tail position.  Also, the JIT compilers cannot optimize the
trampoline, as the functions it will have to call, and their number of
arguments, are unknown.

-- Jerome