From: Frederic van der Plancke <fvdp@decis.be>
To: Ocaml <caml-list@inria.fr>
Subject: Re: [Caml-list] lazy vs function for values that are used once at most
Date: Wed, 30 Jun 2004 14:44:32 +0000 [thread overview]
Message-ID: <40E2D1D0.53852BC@decis.be> (raw)
In-Reply-To: <d61254fb0406300721714b8eb@mail.gmail.com>
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
prev parent reply other threads:[~2004-06-30 14:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-06-30 13:31 henri dubois-ferriere
2004-06-30 13:39 ` Jon Harrop
2004-06-30 14:21 ` henri dubois-ferriere
2004-06-30 14:44 ` Frederic van der Plancke [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=40E2D1D0.53852BC@decis.be \
--to=fvdp@decis.be \
--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).