Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jerome Vouillon <Jerome.Vouillon@pps.jussieu.fr>
To: Yitzhak Mandelbaum <yitzhakm@CS.Princeton.EDU>
Cc: Jerome Vouillon <Jerome.Vouillon@pps.jussieu.fr>,
	caml-list@yquem.inria.fr
Subject: Re: [Caml-list] [ANN] Js_of_ocaml version 1.0
Date: Mon, 13 Dec 2010 16:45:35 +0100	[thread overview]
Message-ID: <20101213154535.GA30270@pps.jussieu.fr> (raw)
In-Reply-To: <0C2C6562-3389-4B61-B0E2-69EF3EAB1418@cs.princeton.edu>

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
does.

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


      reply	other threads:[~2010-12-13 15:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-13 13:06 Jerome Vouillon
2010-12-13 14:58 ` [Caml-list] " Yitzhak Mandelbaum
2010-12-13 15:45   ` Jerome Vouillon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101213154535.GA30270@pps.jussieu.fr \
    --to=jerome.vouillon@pps.jussieu.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=yitzhakm@CS.Princeton.EDU \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox