From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA08745 for caml-redistribution; Wed, 24 Mar 1999 15:17:54 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA11920 for ; Tue, 23 Mar 1999 18:12:41 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.8.7/8.8.7) with ESMTP id SAA03870; Tue, 23 Mar 1999 18:12:28 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA12692; Tue, 23 Mar 1999 18:12:27 +0100 (MET) Message-ID: <19990323181227.25036@pauillac.inria.fr> Date: Tue, 23 Mar 1999 18:12:27 +0100 From: Xavier Leroy To: James Hague , caml-list@inria.fr Subject: Re: Numeric programming efficiency question References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: ; from James Hague on Mon, Mar 22, 1999 at 12:33:11PM -0600 Sender: weis > type vector = {x: float; y: float; z: float};; > let vadd a b = {x = a.x +. b.x; y = a.y +. b.y; z = a.z +. b.z};; > let vec (a,b,c) = {x=a; y=b; z=c};; > vadd vec(1.0,2.0,3.0) vec(10.0,20.0,30.0);; > > I'm curious if the "shape changing" vec routine is optimized away in such > an expression. I would expect it to be, but that's just the wishful > programmer in me. The "vec" function is actually small enough to fall under the default inlining threshold, and so it is inlined at the points of call. In your example above (which should read vadd (vec(1.0,2.0,3.0)) vec((10.0,20.0,30.0));; actually), the inlining doesn't work because it conflicts with an earlier optimization on constant data structures (this will have to be fixed some day). But in more complex examples such as let f x x' = vadd (vec(x +. x', 0.0, 0.0)) (vec (x -. x', 0.0, 0.0)) the calls to "vec" are really inlined away, and the intermediate results x +. x' and x -. x' are not heap-allocated separately. So, it's not too bad, although it might not generate optimal code all the time due to the rather simple-minded inlining and unboxing algorithms used in ocamlopt. - Xavier Leroy