caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Berke Durak <berke@altern.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Module (re)construction cost
Date: Fri, 27 Jul 2001 15:25:21 +0200	[thread overview]
Message-ID: <20010727152521.A28238@pauillac.inria.fr> (raw)
In-Reply-To: <20010722101845.A31393@localhost.localdomain>; from berke@altern.org on Sun, Jul 22, 2001 at 10:18:45AM +0200

> Does building a functorized module cost anything at all ?

There is one overhead, which affects mostly ocamlopt.  Functions in
the functor body are compiled without knowledge of the functor
argument, and hence will use the generic, unoptimized calling protocol
to invoke functions from the functor parameter.  Consider:

module F(X : sig val f : int -> int end) =
  struct
    let g x = ... f x ...
  end

module A = struct let f x = ... end

module B = F(A)

let _ = B.g 3

Calls from B.g to A.f will be unoptimized (no inlining, no special
entry point for curried or tupled functions).  However, the call to
B.g is optimized as usual.  

In contrast, consider the same code without functors:

module A = struct let f x = ... end

module B = struct let g x = ... A.f x ... end

Here, the call from B.g to A.f is optimized.

> i.e. does functor
> application cost anything (time ? memory ?).

Evaluating the functor application itself is very cheap, it just
builds a tuple of values from a tuple of values.  Moreover, this takes
place at program start-up time, i.e. not often.  The main hidden cost
is the lack of optimization in certain function calls as described
above.

- Xavier Leroy
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


  reply	other threads:[~2001-07-27 13:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-22  8:18 Berke Durak
2001-07-27 13:25 ` Xavier Leroy [this message]
2001-07-27 14:09   ` Markus Mottl
2001-07-27 17:51     ` William Chesters

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=20010727152521.A28238@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=berke@altern.org \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).