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
inlining functions called through functor parameters?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: inlining functions called through functor parameters?
> While searching the Caml mailing list archive, I found
> a message from Xavier Leroy, posted on Tue Jun 23 1998,
> in which he describes the fact that:
> "... it is true that functions taken from the
>  functor parameter are always called via their closures".
> I was wondering if this is still true (since 1998 is a long
> time ago, in internet time at least), and if there are any plans
> to implement more inlining for such functions.

Yes, this is still true.  So far, the body of a functor is compiled
only once (at the point where it's defined), and this precludes
inlining of the functions contained in the functor parameter (consider
two applications of the functor).

> The reason I ask is because I'm writing a couple of modules where
> lots of small funtions are called via a functor parameter, and
> I'm wondering if it's worth the trouble to inline them "by hand".

If the functor is applied only once, you could turn it into a
structure that references directly its argument; this will enable
automatic inlining.  Otherwise, and assuming that's the performance
bottleneck in your program, it could be worth the effort to inline
manually some of the functions.

All the best,

- Xavier Leroy