From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 4489BBC69 for ; Wed, 4 Jul 2007 16:35:04 +0200 (CEST) Received: from ptb-relay01.plus.net (ptb-relay01.plus.net [212.159.14.212]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l64EZ3M5032248 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 4 Jul 2007 16:35:04 +0200 Received: from [80.229.56.224] (helo=beast.local) by ptb-relay01.plus.net with esmtp (Exim) id 1I65wc-0007jm-C0 for caml-list@yquem.inria.fr; Wed, 04 Jul 2007 15:35:02 +0100 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Which function is consing? Date: Wed, 4 Jul 2007 15:29:26 +0100 User-Agent: KMail/1.9.7 References: <90BAEAF7-0710-44A3-BB2C-5075A2619371@gmail.com> <4a051d930707040712y5ef0a861x2e0c5297e1e20c99@mail.gmail.com> In-Reply-To: <4a051d930707040712y5ef0a861x2e0c5297e1e20c99@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200707041529.26802.jon@ffconsultancy.com> X-Miltered: at discorde with ID 468BB017.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; memoizing:01 allocating:01 afaik:01 ocaml:01 camlp:01 ocaml:01 frog:98 garbage:01 garbage:01 wrote:01 caml-list:01 functions:01 functions:01 tree:02 top-level:02 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