Skip to content

Quickening interpreter #27

@markshannon

Description

@markshannon

This is a simple idea, but very powerful.

Once a code object has been executed a few times, say 8, create a new bytecode array for the instructions.
The new array is not exposed to the rest of the VM and definitely not to the C or Python APIs.

Because it is private, it can be freely modified at runtime, which allows a number of really nice features:

  • Super-instructions can be added without complicating the compiler and associated tools, like dis.
  • Adaptive (self-modifying) instructions are possible. All sorts of fun can be had here 😄
  • Zero overhead debugging. A break-point can be inserted into the private array, at zero runtime cost until the breakpoint is hit.
  • No-trace versions of instructions can be implemented that avoid testing use_tracing when it is known that tracing is off.
    • We only need to do LOAD_FAST, STORE_FAST, LOAD_CONST, POP_TOP, as they account for approx 45% of all instructions.
    • Super instructions composed only of the above are also implicitly "no-trace".

The quickened bytecode should have the same 2 byte format as normal bytecode.
That way only one interpreter is required and it avoids the complexity of switching between interpreters.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions