[Python-Dev] Register-based VM [Was: Possible performance regression]

Neil Schemenauer nas-python at arctrix.com
Tue Feb 26 18:53:50 EST 2019

On 2019-02-27, Greg Ewing wrote:
> Joe Jevnik via Python-Dev wrote:
> > If Python switched to a global stack and global registers we may be able
> > to eliminate a lot of instructions that just shuffle data from the
> > caller's stack to the callee's stack.
> That would make implementing generators more complicated.

Right.  I wonder though, could we avoid allocating the Python frame
object until we actually need it?  Two situations when you need a
heap allocated frame come to mind immediately: generators that are
suspended and frames as part of a traceback.  I guess
sys._getframe() is another.  Any more?

I'm thinking that perhaps for regular Python functions and regular
calls, you could defer creating the full PyFrame object and put the
locals, stack, etc on the C stack.  That would make calling Python
functions a lot similar to the machine calling convention and
presumably could be much faster.  If you do need the frame object,
copy over the data from the C stack into the frame structure.

I'm sure there are all kinds of reasons why this idea is not easy to
implement or not possible.  It seems somewhat possible though.  I
wonder how IronPython works in this respect?  Apparently it doesn't
support sys._getframe().



More information about the Python-Dev mailing list