|When to do inline expansion jhall@whale.WPI.EDU (1993-09-14)|
|Re: When to do inline expansion email@example.com (1993-09-20)|
|Re: When to do inline expansion firstname.lastname@example.org (1993-09-20)|
|Re: When to do inline expansion email@example.com (1993-09-20)|
|Re: When to do inline expansion firstname.lastname@example.org (1993-09-21)|
|Re: When to do inline expansion email@example.com (1993-09-21)|
|Re: When to do inline expansion firstname.lastname@example.org (1993-09-21)|
|Re: When to do inline expansion email@example.com (1993-09-22)|
|Re: When to do inline expansion firstname.lastname@example.org (1993-09-22)|
|[3 later articles]|
|From:||email@example.com (Daniel J. Salomon)|
|Organization:||Computer Science, University of Manitoba, Winnipeg, Canada|
|Date:||Mon, 20 Sep 1993 22:50:19 GMT|
jhall@whale.WPI.EDU (John Clinton Hall) writes:
> How long should a function be (in number of statements) for it to be a
> reasonable speed optimization to perform inline expansion? (For
> simplicity, let's assume that the function is only called once
> throughout the code, and the source language is C.)
There are three principal disadvantages to compiling a function
invocation inline instead of as a machine function call:
1) the compiler will be more complex,
2) compilation may be slower, and
3) more memory may be used by the program.
The first two are irrelevant to the posted question, since the poster
was not interested in compiler complexity or compilation time. If a
function is called in only one place in a program, and the parameters
are only evaluated once, then inline expansion always uses less memory
and runs faster than a function call.
If a function is called in more than one place, then the trade-off
decision to be made is between speed and memory usage; inline code is
always faster but may take more space. (This statement is not always
true for macro calls where the parameters are evaluated every time they
are used.) If the code in a function takes less memory than the code
needed to execute a function call, then inlining would ALWAYS beat
function calling in both speed and space, no matter how many places the
function is invoked.
So the choice between inlining and function calling would have to be
made based on the relative costs of computer time versus memory cost.
A compiler cannot know these relative costs for every application.
For some applications speed is more important than size, and for other
the opposite is true. So a compiler should probably leave the decision
to the programmer, and not try to guess.
Daniel J. Salomon -- salomon@cs.UManitoba.CA
Dept. of Computer Science / University of Manitoba
Winnipeg, Manitoba, Canada R3T 2N2 / (204) 474-8687
Return to the
Search the comp.compilers archives again.