caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Frederic van der Plancke <fvdp@decis.be>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Memory usage/ garbage collection question
Date: Fri, 14 Oct 2005 10:51:55 +0000	[thread overview]
Message-ID: <434F8DCB.550F88CB@decis.be> (raw)
In-Reply-To: <20051014102749.GA15524@furbychan.cocan.org>



Richard Jones wrote:
> 
> On Fri, Oct 14, 2005 at 04:58:59AM -0500, Seth J. Fogarty wrote:
> > I do not see why iterating through a list that consumed a lot of
> > memory should (innately) cause you to thrash. What is thrashing?
> > access to the disk? Garbage collection?
> 
> That's where I'm not really sure, except that it is observably
> thrashing.  Since it's a simple iteration, I guess that would
> implicate the GC?
> 
> > No, because you have bound rows to a name. Now, I believe if rows is
> > returned by a function, and is NOT bound by name in that function, it
> > can be garbage collected. I.E.
> 
> Ah OK ... I'm interested though: why does binding a value to a name
> cause problems?  Surely at this level (ocamlopt generated code) there
> ought to be no difference between a named value and an unnamed one?
> 
> Rich.

Perhaps the problem is not the name, but the fact that when you write

    List.iter f rows

the compiler isn't going to go great lengths in optimizing out the reference to rows before the call to List.iter, since the optimisation probably isn't free and the compiler (and compiler writers) don't know in advance how worthwhile it would be.

If the call to List.iter was a tail call the compiler would probably be forced to optimise rows out.

Hence my 0.02 cents worth untested idea: you might try and use tail call optimisation to get rid of that reference.

say
   let do_work () = 
      let rows = ... in
      List.iter (...) rows

Frédéric


  reply	other threads:[~2005-10-14 10:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-14  9:49 Richard Jones
2005-10-14 10:02 ` [Caml-list] " skaller
2005-10-14 10:08 ` Olivier Andrieu
     [not found] ` <c7ee61120510140258q5b7f393l8e3c2c3d45f49008@mail.gmail.com>
2005-10-14 10:27   ` Richard Jones
2005-10-14 10:51     ` Frederic van der Plancke [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-10-14  9:36 yoann padioleau
2005-10-14 10:10 ` Richard Jones
2005-10-14 10:07   ` Gerd Stolpmann

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=434F8DCB.550F88CB@decis.be \
    --to=fvdp@decis.be \
    --cc=caml-list@yquem.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).