Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: James Hague <jhague@dadgum.com>, caml-list@inria.fr
Subject: Re: Numeric programming efficiency question
Date: Tue, 23 Mar 1999 18:12:27 +0100	[thread overview]
Message-ID: <19990323181227.25036@pauillac.inria.fr> (raw)
In-Reply-To: <Pine.LNX.3.96.990322122948.12166A-100000@babba.advancenet.net>; from James Hague on Mon, Mar 22, 1999 at 12:33:11PM -0600

> 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




  reply	other threads:[~1999-03-24 14:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-22 18:33 James Hague
1999-03-23 17:12 ` Xavier Leroy [this message]
1999-03-23 19:32   ` James Hague

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=19990323181227.25036@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=jhague@dadgum.com \
    /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