Version française
Home     About     Download     Resources     Contact us    
Browse thread
parameter passing optimizations
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Warren Harris <warren@m...>
Subject: parameter passing optimizations

--Apple-Mail-32--871024726
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed;
	delsp=yes
Content-Transfer-Encoding: 7bit

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


--Apple-Mail-32--871024726
Content-Disposition: attachment;
	filename=smime.p7s
Content-Type: application/pkcs7-signature;
	name=smime.p7s
Content-Transfer-Encoding: base64

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIKlzCCBREw
ggP5oAMCAQICAQEwDQYJKoZIhvcNAQEEBQAwgb8xCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxp
Zm9ybmlhMRYwFAYDVQQHEw1TYW4gRnJhbmNpc2NvMSMwIQYDVQQKExpNZXRhd2ViIFRlY2hub2xv
Z2llcywgSW5jLjEbMBkGA1UECxMSTWV0YXdlYiBPcGVyYXRpb25zMSEwHwYDVQQDExhNZXRhd2Vi
IFJvb3QgQ2VydGlmaWNhdGUxHjAcBgkqhkiG9w0BCQEWD29wc0BtZXRhd2ViLmNvbTAeFw0wNjEw
MTcxNjAyNTRaFw0xNjEwMTQxNjAyNTRaMIGrMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZv
cm5pYTEjMCEGA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