Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the dynamic nature of Python interoperate with PyPy's ability to inline functions?

Tags:

python

jit

pypy

Suppose you have a function like f that calls a function m.g:

def f(x):
    return m.g(x, 2*x, x+1)

and f gets called a lot, so PyPy JITs it and inlines m.g into it. What if later, due to the "dynamic" nature of Python, m.g gets replaced by something else: Will the old JITed version of f be discarded right away, or could it still be called accidentally?

Also, what if your program does these redefinitions a lot, can the discarded JITed versions cause a memory leak?

like image 939
MWB Avatar asked Dec 02 '25 09:12

MWB


1 Answers

To answer your last question: "if your program does these redefinitions a lot, can the discarded JITed versions cause a memory leak?" This is a good question, and the answer might be yes in some cases. The bad case might be if g is a function you just created with exec or eval, so that there is an unbounded number of function objects that end up being called here. This is a problem that we thought about fixing in the past, but never got around to do it. If you are experiencing what looks like a leak and have isolated this part of the code, then I'd say chances are that it is exactly what you are fearing. In that case, I'd recommend to write a mail to [email protected] or come to #pypy on irc.freenode.net to describe your case.

like image 106
Armin Rigo Avatar answered Dec 05 '25 07:12

Armin Rigo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!