### Benefits and Drawbacks of Inlining

Inlining user code eliminates the overhead of the function call and linkage, and exposes the function's code to the optimizer, resulting in faster code performance. Inlining produces the best results when the overhead for the function is significant; for example, when functions are called within nested loops.

The best candidates for inlining are small functions that are called often.

To improve performance further:

- Use constant arguments in inlined functions whenever possible. Functions with constant arguments provide more opportunities for optimization.
- If you have a function that is called many times from a few functions, but infrequently from others, create a copy of the function with a different name and inline it only in the functions that call it often.
- Turn optimization on.

Drawbacks of Inlining
Inlining user code usually results in a larger executable module. Because of the extra optimizations that can be performed, the difference in size may be less than the size of the function multiplied by the number of calls.

Inlining can also result in slower program performance, especially if you use auto-inlining. Because auto-inlining looks only at the number of ACUs for a function, the functions that are inlined are not always the best candidates for inlining. As much as possible, use the _Inline or inline keyword to choose the functions to be inlined.

When you use inlining, you need more stack space. When a function is called, its local storage is allocated at the time of the call and freed when it returns to the calling function. If that same function is inlined, its storage is allocated when the function that calls it is entered, and is not freed until that calling function ends. Ensure that you have enough stack space for the local storage of the inlined functions, in order to avoid a stack overflow.

Optimize Your Application

Tips for Inlining