# Adding inline in Python

**URL:** <https://discuss.python.org/t/adding-inline-in-python/13532>\
**Category:** Ideas\
**Created:** [February 6, 2022, 8:10am UTC](https://discuss.python.org/t/adding-inline-in-python/13532 "2022-02-06T08:10:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![1604042736](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/1604042736/32/6154_2.png) [@1604042736](https://discuss.python.org/u/1604042736)\
**Post date:** [February 6, 2022, 8:10am UTC](https://discuss.python.org/t/adding-inline-in-python/13532/1 "2022-02-06T08:10:23Z")

</div>

This is the same as the inline function in C.  
Speed up by expanding shorter functions.  
I don’t know if this is necessary,at least this is necessary in one of my projects.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [February 6, 2022, 9:02am UTC](https://discuss.python.org/t/adding-inline-in-python/13532/2 "2022-02-06T09:02:10Z")

</div>

Why is it “necessary” in one of your projects? Explain what your project  
does that it needs to inline code?

Can your project really wait until Python 3.11 or maybe 3.12 is  
released, in 1-3 years, before using inline code?

---

<div class="post-metadata">

**Author:** ![1604042736](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/1604042736/32/6154_2.png) [@1604042736](https://discuss.python.org/u/1604042736)\
**Post date:** [February 6, 2022, 10:37am UTC](https://discuss.python.org/t/adding-inline-in-python/13532/3 "2022-02-06T10:37:16Z")

</div>

Because my project will frequently call some short functions, I think it will be very time-consuming.

---

<div class="post-metadata">

**Author:** ![steven.daprano](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/steven.daprano/32/1083_2.png) [@steven.daprano](https://discuss.python.org/u/steven.daprano)\
**Post date:** [February 6, 2022, 11:11am UTC](https://discuss.python.org/t/adding-inline-in-python/13532/4 "2022-02-06T11:11:48Z")

</div>

You “think” it will be very time consuming, or you have measured it and  
the function call overhead is significant?

Here are some quotes from some giants of computer science:

“Premature optimization is the root of all evil in programming.”  
C.A.R. Hoare

“More computing sins are committed in the name of efficiency (without  
necessarily achieving it) than for any other single reason — including  
blind stupidity.” W.A. Wulf

Don’t guess what is making it slow, measure it and find out. Otherwise  
you will waste one or two years waiting for Python to add inlining, and  
discover that it makes no difference to your code at all.

If your functions are small enough that the function call overhead makes  
a difference, chances are they are small enough that you can inline them  
yourself.

---

<div class="post-metadata">

**Author:** ![TobiasHT](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/tobiasht/32/23304_2.png) [@TobiasHT](https://discuss.python.org/u/TobiasHT)\
**Post date:** [February 6, 2022, 12:14pm UTC](https://discuss.python.org/t/adding-inline-in-python/13532/5 "2022-02-06T12:14:21Z")

</div>

I’ve rised a similar issue before. Perhaps you’ll learn more from what everyone had to say about it.

> [@Inline Python functions and methods](https://discuss.python.org/t/inline-python-functions-and-methods/12412):
>
> The Python community has a 5 year plan to push the limit of speed in Python. One of the things that reduces Python execution speed is calling methods or functions that are not in the nearest scope. My suggestion is to introduce inline functions just as they are in C. They can be defined as global functions or class methods but are created in the scope of the function that is calling it at parsetime. I also don’t think it’ll be hard to adapt. inline functions might look something like: inline d…
