From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA28568; Fri, 27 Jul 2001 15:25:23 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA26724 for ; Fri, 27 Jul 2001 15:25:22 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f6RDPLf29005; Fri, 27 Jul 2001 15:25:21 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA28528; Fri, 27 Jul 2001 15:25:21 +0200 (MET DST) Date: Fri, 27 Jul 2001 15:25:21 +0200 From: Xavier Leroy To: Berke Durak Cc: caml-list@inria.fr Subject: Re: [Caml-list] Module (re)construction cost Message-ID: <20010727152521.A28238@pauillac.inria.fr> References: <20010722101845.A31393@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20010722101845.A31393@localhost.localdomain>; from berke@altern.org on Sun, Jul 22, 2001 at 10:18:45AM +0200 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > 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