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

Victor Stinner vstinner at redhat.com
Tue Feb 26 17:08:07 EST 2019

Le mar. 26 févr. 2019 à 21:58, Neil Schemenauer <nas-python at python.ca> a écrit :
> It seems his name doesn't appear in the readme or source but I think
> Rattlesnake was Skip Montanaro's project.  I suppose my idea of
> unifying the local variables and the registers could have came from
> Rattlesnake.  Very little new in the world. ;-P

In my implementation, constants, local variables and registers live
all in the same array: frame.f_localsplus. Technically, there isn't
much difference between a constant, local variable or a register. It's
just the disassembler which has to worry to display "R3" or "x"
depending on the register index ;-)

There was a LOAD_CONST_REG instruction in my implementation, but it
was more to keep a smooth transition from existing LOAD_CONST
instruction. LOAD_CONST_REG could be avoided to pass directly the
constant (ex: as a function argument).

For example, I compiled "range(2, n)" as:

LOAD_CONST_REG       R0, 2 (const#2)
LOAD_GLOBAL_REG      R1, 'range' (name#0)
CALL_FUNCTION_REG    4, R1, R1, R0, 'n'

Whereas it could be just:

LOAD_GLOBAL_REG      R1, 'range' (name#0)
CALL_FUNCTION_REG    4, R1, R1, <const #2>, 'n'

Compare it to stack-based bytecode:

LOAD_GLOBAL          0 (range)
LOAD_CONST           2 (const#2)
LOAD_FAST            'n'
CALL_FUNCTION        2 (2 positional, 0 keyword pair)

Night gathers, and now my watch begins. It shall not end until my death.

More information about the Python-Dev mailing list