From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id A66F1BC57 for ; Wed, 1 Sep 2010 14:30:48 +0200 (CEST) X-IronPort-AV: E=Sophos;i="4.56,304,1280700000"; d="scan'208";a="66508991" Received: from peermanence.saclay.inria.fr (HELO [195.83.212.205]) ([195.83.212.205]) by mail1-relais-roc.national.inria.fr with ESMTP; 01 Sep 2010 14:30:48 +0200 Message-ID: <4C7E4745.3070206@inria.fr> Date: Wed, 01 Sep 2010 14:29:57 +0200 From: Fabrice Le Fessant User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: Ethan Burns Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Re: Question about float refs. References: <20100823.140626.634675953541672216.Christophe.Troestler+ocaml@umons.ac.be> <031b01cb4944$77110900$65331b00$@com> <4C7E0F60.6030406@inria.fr> In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; unboxed:01 ocamlopt:01 compiler:01 compiler:01 unboxed:01 iteration:01 printf:01 printf:01 allocations:01 ocaml:01 burns:98 wrote:01 wrote:01 caml-list:01 argument:02 Ethan Burns wrote, On 09/01/2010 11:54 AM: > On Wed, Sep 1, 2010 at 4:31 AM, Fabrice Le Fessant > wrote: >> If you replace (!r +. 0.) by (!r), you are passing the content of the >> reference as an argument to the function. Function arguments are not >> unboxed in ocamlopt, so the compiler sees a boxed occurrence of the >> float, and so must allocate it. The compiler could decide to have the >> float both as boxed and unboxed values, but since the reference is >> modified in the loop, there would be a risk of inconsistency, and so the >> compiler decides to have only a boxed value, and so the loop is much >> slower since it has to allocate the float at each iteration (the >> reference itself is probably not allocated). > > Is there a reason that it can not decide to leave the float unboxed > until right before the Printf.printf call? This way it would be > modified in the loop without any allocations and then would be placed > in a box only when the box is finally needed. Yes, that would work. I suppose the reason is just that the analysis to discover that is much more complex and expensive, and the result is not always successful, so it was not clear it was worth it for typical OCaml applications. --Fabrice