Browse thread
Which function is consing?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jon Harrop <jon@f...> |
| Subject: | Re: [Caml-list] Which function is consing? |
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