Browse thread
[Caml-list] inlining of functions
- Markus Mottl
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ 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 |
Hello,
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
and:
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.
Regards,
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 markus@oefai.at
Austrian Research Institute
for Artificial Intelligence http://www.oefai.at/~markus
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr