caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Brian Hurt <bhurt@spnz.org>
To: Joel Reymont <joelr1@gmail.com>
Cc: "Markus E.L." <ls-ocaml-developer-2006@m-e-leypold.de>,
	caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Which function is consing?
Date: Wed, 4 Jul 2007 12:05:44 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0707041123360.5269@localhost> (raw)
In-Reply-To: <1E47C897-547E-4B65-8DB8-46228F438C1A@gmail.com>



On Wed, 4 Jul 2007, Joel Reymont wrote:

> What I would like to find out is how much memory each function allocates. I 
> would like to minimize memory allocations as they put pressure on the garbage 
> collector.

Are you trying to track down a specific performance problem, or just 
trying to avoid allocation in general?

If it's the former, I've had good luck just hand analyzing functions. 
Once you know the boxing rules, each block allocated in memory has one tag 
word associated with it.  So if I see "x :: lst" in my code, I know that 
just allocated 3 words- a tag word for the list block, plus a value and a 
next pointer.  And so on.  One of the nice things about Ocaml vr.s Haskell 
is that this sort of analysis is much easier to do in Ocaml.

If you're just trying to reduce memory allocation in general, my advice is 
to not bother, unless you have evidence that 1) performance isn't 
acceptable, 2) higher level optimizations (for example, replacing O(N^2) 
operations with O(N log N) operations) either cannot be applied or would 
be ineffective, and 3) garbage collection costs from excessive allocation 
is the problem.

One comment I will make: it's not unusual for C/C++ programs to spend 
considerable amount of time allocating and deallocating objects as well, 
see:
ftp://ftp.cs.colorado.edu/pub/techreports/zorn/CU-CS-665-93.ps.Z

And note that this study does not include any overhead of deciding if an 
object is freeable, which Ocaml's GC does as well.  C/C++ allocate and 
deallocate a heck of a lot less, but the cost of allocating and 
deallocating is a heck of a lot higher.  The difference is that in Ocaml, 
all of these costs are reported as one big number- "hey, you're spending 
30% of your time in GC!"  While if you were spending 30% of your time in 
destructors deciding which objects can be freed yet or not, since that 
time is spread over a bunch of different functions, it's much less 
obvious.

Brian


      parent reply	other threads:[~2007-07-04 15:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-04 10:52 Joel Reymont
2007-07-04 14:12 ` [Caml-list] " Christopher L Conway
2007-07-04 14:29   ` Jon Harrop
2007-07-04 14:29 ` Markus E.L.
2007-07-04 14:24   ` Joel Reymont
2007-07-04 14:45     ` Bünzli Daniel
2007-07-04 18:19       ` Jon Harrop
2007-07-04 16:05     ` Brian Hurt [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=Pine.LNX.4.64.0707041123360.5269@localhost \
    --to=bhurt@spnz.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=joelr1@gmail.com \
    --cc=ls-ocaml-developer-2006@m-e-leypold.de \
    /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).