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 QAA25449; Wed, 30 Jun 2004 16:42:24 +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 QAA25440 for ; Wed, 30 Jun 2004 16:42:23 +0200 (MET DST) Received: from decis.be ([194.78.219.157]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i5UEgMSH029008 for ; Wed, 30 Jun 2004 16:42:22 +0200 Received: from decis.be by decis.be (MDaemon.PRO.v7.1.0.R) with ESMTP id md50000036345.msg for ; Wed, 30 Jun 2004 16:44:35 +0200 Message-ID: <40E2D1D0.53852BC@decis.be> Date: Wed, 30 Jun 2004 14:44:32 +0000 From: Frederic van der Plancke Organization: Decis X-Mailer: Mozilla 4.77 [en] (Windows NT 5.0; U) X-Accept-Language: en,fr-BE,fr MIME-Version: 1.0 To: Ocaml Subject: Re: [Caml-list] lazy vs function for values that are used once at most References: <200406301439.15289.postmaster@jdh30.plus.com> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Authenticated-Sender: fplancke@decis.be X-Spam-Processed: decis.be, Wed, 30 Jun 2004 16:44:35 +0200 (not processed: message from valid local sender) X-MDRemoteIP: 192.168.0.20 X-Return-Path: fvdp@decis.be X-MDaemon-Deliver-To: caml-list@inria.fr Reply-To: fvdp@decis.be X-Miltered: at concorde with ID 40E2D14E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; plancke:01 fvdp:01 caml-list:01 memoization:01 indirection:01 slower:01 int:01 lazy:02 lazy:02 exception:02 unit:03 overhead:03 overhead:03 henri:03 henri:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk henri dubois-ferriere wrote: > > ok. > actually, i should refine my question a little further: > in the vast majority of cases, the value is *not* used at all. > so i suppose the memoization overhead you mention does not occur when > a lazy value is not forced. > > so, the question then becomes: > > any difference in overhead between creating > (lazy v) > and > (fun () -> v) > > ? > thanks for any insights > henri Sure. The value (lazy ...) is something significantly more complex than (fun () -> ...) and contains a (fun () -> ...) internally anyway. So it has overhead. See the source (lazy.ml) if you want to be sure and precise. For instance (lazy 33) has type (int Lazy.t) where Lazy.t is defined as such: type 'a status = | Delayed of (unit -> 'a) | Value of 'a | Exception of exn ;; type 'a t = 'a status ref;; So before computation is forced, (lazy 33) = ref (Delayed (fun () -> 33)) which means 2 levels of indirection more -> somewhat slower access, 2 words of memory waste, more strain on the GC. Frédéric. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners