# When exactly does the Erlang compiler inline code?

**URL:** <https://erlangforums.com/t/when-exactly-does-the-erlang-compiler-inline-code/1302>\
**Category:** Questions / Help\
**Tags:** optimization, compiler\
**Created:** [April 9, 2022, 10:50am UTC](https://erlangforums.com/t/when-exactly-does-the-erlang-compiler-inline-code/1302 "2022-04-09T10:50:42Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![bjorng](https://erlangforums.com/user_avatar/erlangforums.com/bjorng/32/174_2.png) [@bjorng](https://erlangforums.com/u/bjorng)\
**Post date:** [April 11, 2022, 5:16am UTC](https://erlangforums.com/t/when-exactly-does-the-erlang-compiler-inline-code/1302/4 "2022-04-11T05:16:34Z")

</div>

> [@Qqwy](#):
>
> However, it is a bit vague in one particular area of interest: Will the compiler ever inline functions from other modules (i.e. ‘remote’ functions)?  
> There is the separate `inline_list_funcs` option, but I wonder if it is possible to convince the compiler to do something similar for other modules in certain situations

No, the compiler will never inline code from other modules. When the `inline_list_funcs` option is given, the compiler uses hard-coded knowledge of a few of the functions in the `lists` module.

> [@hackerjones](#):
>
> I don’t believe remote calls could be inlined. How would hot code upgrades work?

Hot code upgrades would be much more complicated if inlining from remote modules were allowed. One way to handle it would be for the loader to load and unload all modules in an application (or other groups of modules) all at once. Another way would be for the compiler to generate code both with and without inlining and let the loader make sure that the correct version of the code would be used.

We have not tried to implement either of those ways to handle inlining combined with hot code upgrading, because all experiments we have done so far with inlining code between modules in applications such as `compiler` and `dialyzer` have been disappointing. The issue seems to be that function calls in BEAM are very fast, and thus inlining will only gain performance if the inlined code can be simplified. If the code cannot be simplified, inlining will increase the code size, which usually results in worse performance.

---

_[View the full topic](https://erlangforums.com/t/when-exactly-does-the-erlang-compiler-inline-code/1302)._
