From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Which function is consing?
Date: Wed, 4 Jul 2007 15:29:26 +0100 [thread overview]
Message-ID: <200707041529.26802.jon@ffconsultancy.com> (raw)
In-Reply-To: <4a051d930707040712y5ef0a861x2e0c5297e1e20c99@mail.gmail.com>
On Wednesday 04 July 2007 15:12:38 Christopher L Conway wrote:
> I'm not sure I understand you correctly, but it's highly doubtful that
> consing is the hotspot in your program.
The garbage collector often takes 30% of the CPU but when it is taking 90% of
the CPU time you want to know where all of the garbage is coming from in
order to optimize away its allocation. This is typically by avoiding
overly-eager recomputation or by memoizing results. I believe Joel
means "allocation" when he says "consing", so he isn't just referring to list
construction.
To solve this problem you need to know which functions in the call tree are
allocating heavily. The GC module provides the necessary statistics but
(AFAIK) there are no tools to automate this for OCaml as there are for F# and
other languages.
So the simple solution is to wrap your functions in checks by hand and log the
results. This is very tedious. Perhaps someone would like to write a camlp4
macro that wraps all top-level function definitions with memory profiling
calls?
So:
let f x = ...
is supplemented with:
let f x = ...
let f x =
let __ = (Gc.stat()).Gc.major_words in
let f_x = f x in
gc_log "f" ((Gc.stat()).Gc.major_words - __);
f_x
How does that sound?
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The OCaml Journal
http://www.ffconsultancy.com/products/ocaml_journal/?e
next prev parent reply other threads:[~2007-07-04 14:35 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 [this message]
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
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=200707041529.26802.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--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