Question

If I have a function that is called in few places in my module, does the virtual machine compiles it to native code only the first time the function is executed and than use the cashed code on the other calls? (like .NET jit compiler)

Was it helpful?

Solution

In CPython (the standard Python implementation) the first time a Python module is imported, it's compiled to bytecode and stored in a .pyc file. From then on, the .pyc file is read and interpreted by the VM when needed. Once the .pyc is read into memory, the bytecode is in memory, and interpreted by the VM when the function is called.

CPython never compiles Python code to native executable code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top