caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Warren Harris <warren@metaweb.com>
To: caml-list caml-list <caml-list@yquem.inria.fr>
Subject: parameter passing optimizations
Date: Tue, 5 Aug 2008 09:39:03 -0700	[thread overview]
Message-ID: <9CA17B22-757C-4ED0-866C-4C44E73DB423@metaweb.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2786 bytes --]

I've been wondering whether the ocaml compiler does any sort of  
parameter passing optimizations for data structures, e.g. stack  
allocating, or destructuring them when it can determine their scope  
does not escape the call. My first conclusion is that it does for  
tuples only, but I wanted to see what others might know.

I wrote a number of simple test programs that each pass 6 arguments  
through 2 levels of functions by a number of means (main calls foo 1M  
times, foo calls bar once). For 1M iterations, the times I saw  
(optimized) are posted below.

It looks like the case of passing parameters in a tuple doesn't  
allocate (since the number of minor words is the same as the  
positional parameters case). However, it still seems to run more than  
an order of magnitude slower so perhaps it loses the benefits of  
register allocation (?).

Warren


let bar a b c d e f =
   a + b + c + d + e + f

minor_words: 7950
promoted_words: 2251
major_words: 2266
minor_collections: 1
major_collections: 0
heap_words: 61440
heap_chunks: 1
top_heap_words: 61440
live_words: 2266
live_blocks: 354
free_words: 59174
free_blocks: 1
largest_free: 59174
fragments: 0
compactions: 0

real	0m0.860s
user	0m0.835s
sys	0m0.017s


let bar (a, b, c, d, e, f) =
   a + b + c + d + e + f

minor_words: 7950
promoted_words: 2251
major_words: 2266
minor_collections: 1
major_collections: 0
heap_words: 61440
heap_chunks: 1
top_heap_words: 61440
live_words: 2266
live_blocks: 354
free_words: 59174
free_blocks: 1
largest_free: 59174
fragments: 0
compactions: 0

real	0m11.067s
user	0m10.942s
sys	0m0.037s


let bar (Foo(a, b, c, d, e, f)) =
   a + b + c + d + e + f

minor_words: 7000224061
promoted_words: 2251
major_words: 2266
minor_collections: 213629
major_collections: 0
heap_words: 61440
heap_chunks: 1
top_heap_words: 61440
live_words: 2266
live_blocks: 354
free_words: 59174
free_blocks: 1
largest_free: 59174
fragments: 0
compactions: 0

real	0m17.443s
user	0m17.176s
sys	0m0.089s


let bar {a=a; b=b; c=c; d=d; e=e; f=f} =
   a + b + c + d + e + f

minor_words: 7000223886
promoted_words: 2251
major_words: 2266
minor_collections: 213629
major_collections: 0
heap_words: 61440
heap_chunks: 1
top_heap_words: 61440
live_words: 2266
live_blocks: 354
free_words: 59174
free_blocks: 1
largest_free: 59174
fragments: 0
compactions: 0

real	0m16.314s
user	0m16.167s
sys	0m0.059s


let bar ?(a=0) ?(b=0) ?(c=0) ?(d=0) ?(e=0) ?(f=0) () =
   a + b + c + d + e + f

minor_words: 12002946309
promoted_words: 2251
major_words: 2266
minor_collections: 366300
major_collections: 0
heap_words: 61440
heap_chunks: 1
top_heap_words: 61440
live_words: 2266
live_blocks: 354
free_words: 59174
free_blocks: 1
largest_free: 59174
fragments: 0
compactions: 0

real	0m33.036s
user	0m32.648s
sys	0m0.156s


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3739 bytes --]

             reply	other threads:[~2008-08-05 16:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-05 16:39 Warren Harris [this message]
2008-08-05 17:28 ` [Caml-list] " Stéphane Glondu

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=9CA17B22-757C-4ED0-866C-4C44E73DB423@metaweb.com \
    --to=warren@metaweb.com \
    --cc=caml-list@yquem.inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).