* parameter passing optimizations
@ 2008-08-05 16:39 Warren Harris
2008-08-05 17:28 ` [Caml-list] " Stéphane Glondu
0 siblings, 1 reply; 2+ messages in thread
From: Warren Harris @ 2008-08-05 16:39 UTC (permalink / raw)
To: caml-list caml-list
[-- 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 --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] parameter passing optimizations
2008-08-05 16:39 parameter passing optimizations Warren Harris
@ 2008-08-05 17:28 ` Stéphane Glondu
0 siblings, 0 replies; 2+ messages in thread
From: Stéphane Glondu @ 2008-08-05 17:28 UTC (permalink / raw)
To: Warren Harris; +Cc: caml-list caml-list
Warren Harris wrote:
> 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.
Maybe you can check it out yourself with the -dinstr option of ocamlc,
or the -S option of ocamlopt.
Cheers,
--
Stéphane
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-08-05 17:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-05 16:39 parameter passing optimizations Warren Harris
2008-08-05 17:28 ` [Caml-list] " Stéphane Glondu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox