Re: ocaml inlining

From: Mark Hayden (hayden@cs.cornell.edu)
Date: Thu Mar 27 1997 - 21:21:34 MET


Date: Thu, 27 Mar 1997 15:21:34 -0500
Message-Id: <199703272021.PAA01643@gulag.cs.cornell.edu>
From: Mark Hayden <hayden@cs.cornell.edu>
To: caml-list@pauillac.inria.fr
Subject: Re: ocaml inlining

>> In the recent versions of Ocaml, are functions inlined
>> across modules? Across files?
>
>Yes to both. (Remember: this applies only to the native-code compiler.)
>The body of an inlinable function is stored in the .cmx file for its
>defining module, thus it can be inlined from other modules.
>
>> If so, what is the effect of
>> compiling several files with different levels of inlining?
>
>The inlining level (-inline n) is taken into account when compiling a
>function definition, but not when compiling a call to this function.
>If the function is small enough (w.r.t. the inlining level at that
>time), it is marked inlinable, and all uses of this function will
>inline its body, regardless of the value of -inline at the time of use.

   Doing things in this fashion seems to prevent functions
in the standard library from being inlined (other than with
the default level). It would seem that there could be many
advantages to inlining functions such as List.iter. Is
there any way to get around this limitation without
recompiling & reinstalling the standard library or compiling
private versions of the standard library modules?
   Also, I tried compiling the following to see what
assembly code was being generated:

  let rec map f = function (* from List module *)
      [] -> []
    | a::l -> let r = f a in r :: map f l

  let list_incr l =
    map (fun i -> succ i) l

Unfortunately, no matter how large an inlining level was
used, the map function would not be inlined. When I looked
at the compiler sources, I found that "let rec" expressions
are never inlined. Is there a reason for this?
  As a final note, I ran some tests to see the effect of
inlining on the size of Ensemble, the system I'm working on.
Ensemble is a distributed communication system with around
30,000 lines of ML code. With varying levels of inlining, I
compiled, linked, and stripped all of Ensemble, and then
printed the size of the resulting executable.

  inline executable
  level size
  0 757024
  1 757424
  2 765584
  3 769776
  4 772928
  8 782032
  16 787488
  20 792064
  24 795136
  28 803056
  32 803056

--Mark



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:10 MET