jw_
jw_

Reputation: 1795

Will performance be obviously negatively impacted If most functions are expanded (e.g. inlined)?

One purpose of function is code reuse. Another possible usage is saving program memory, which also means performance considering I-cache and L2+ cache occupation and main memory bandwidth occupied by instruction fetching.

For curiosity, the question is will the performance of daily software (like a whole OS plus a lot of applications, not just some small benchmarking code) be indeed obviously impacted if all functions of are "expanded"? It is mainly about the impact on cache and main memory instruction bandwidth.

The reason that the impact may be not obvious is that for that much of instructions, it doesn't matter they are copied a lot of times or reused. Also the fact may be that the locality mainly come from loop instead of function calls.

"expand" means whenever a function is called, the whole function is put in place, or equivalently a new copy of the function is created (statically by the "function expanding tool" for normal calls, or dynamically by some "function expanding runtime" for funtion pointer calls) and called there.

"expand" is hard to define for all advanced lanuguage syntax situations (such as lambda/closure etc) and the imagined tool that "expand" source code will be complex. Let's suppose for now only function calls that are simple to expand are expanded and it can even be supposes that all code are written in C. And obviously recursive calls can't be expanded and not fall into a discussion about how program can be expanded which is not the point of the question.

Lets also suppose the computer have enough main memory, since the expanded image of OS plus application could be quite large, like 1TB?

Upvotes: 1

Views: 102

Answers (1)

user16930239
user16930239

Reputation: 9808

Compilers are very efficient nowadays, and a simple kind of "expansion" will always be done by the compiler, also the extend of "expansion" will increase if the build does not use optimization for smaller file size.

From my extensive experience optimizing C codes, I do not think it will be a noticeable difference if use in OS for example, but it is very useful in (for example) image processing.

This could be done manually in C using Macros instead of functions, which will expand functions (in this case Macros) during pre-processing which will result in faster code execution.

EDIT:

It could affect the performance negatively as mentioned here:

  1. Linux kernel coding style documentation
  2. inline function C++

BUT still I don't think in a real scenario it will hurt that much unless the system memory is so little that the increase in executable files size would be enough to overwhelm the memory.

Upvotes: 1

Related Questions