Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] inlining of functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Markus Mottl <markus@o...>
Subject: [Caml-list] inlining of functions

I would like to know why OCaml does not produce the same machine code for:

  let f x =
    let g n = x + n in
    g 1, g 2


  let f x =
    x + 1, x + 2

OCaml obviously performs some inlining, but otherwise produces more
redundant code in the first example. The reason why I ask is that it
often happens that I want to factor out computations that are shared
between different case-arms like in:

  let f x =
    let g y = ... h x y ... in
    match foo with
    | A -> g n
    | B -> g m

It may degrade performance in tight loops quite visibly if there is
extra-code to execute. One would have to use copy&paste to prevent this,
which is not really that elegant.

Markus Mottl

P.S.:  Congratulations to the whole OCaml-team for the recent release
       of OCaml-3.04! You should add some bugs from time to time so
       that people do not get bored marvelling about its unvaryingly
       superb quality! ;)

Markus Mottl                                   
Austrian Research Institute
for Artificial Intelligence        
Bug reports:  FAQ:
To unsubscribe, mail  Archives: