You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pyjion is a JIT compiler. It compiles native CPython bytecode into machine code. Without Pyjion, CPython uses a master evaluation loop (called the frame evaluation loop) to iterate over opcodes
The Pyjion compiler has 3 main stages:
Build a "stack table" of the abstract types at each opcode position
Compile CPython opcodes into CIL opcodes
Emit the CIL opcodes into the .NET EE compiler to convert to native machine code/assembly
Guiding principles
Optimizations must follow these principles:
They must support custom objects (remember that everything can be overidden in Python!)
They must pass the CPython test suite
They must be isolated and testable
They must be atomic and simple
Compiler design
The rough design of the compile stage is to emit isolated CIL opcodes for each bytecode in the compiled frame.
Because of the flexibility of Python's type system, the opcodes will mimic CPython's eval loop:
Take/put references onto a value stack
Call a C API method
Take/put results onto a value stack
Check for errors
Go to next
There is some added complexity, because .NET CIL requires that the value stack is a LIFO stack, whereas CPython implements a value "stack" but actually uses it like an array.
The calling of the C API method is wrapped by the .NET CEE_CALL opcode, which calls a wrapper method implemented in the intrins.cpp file.
Without further optimizations, Pyjion would perform roughly the same as CPython (as fast or slow as the C API methods its calling).
The benefits of Pyjion come from changing the emitted machine code by deterministic observations about the inputs, constants or environment.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
An open thread for people to share ideas for optimisations.
Please check out https://pyjion.readthedocs.io/en/latest/optimizations.html for design principles and existing optimisations.
Overview
Pyjion is a JIT compiler. It compiles native CPython bytecode into machine code. Without Pyjion, CPython uses a master evaluation loop (called the frame evaluation loop) to iterate over opcodes
The Pyjion compiler has 3 main stages:
Guiding principles
Optimizations must follow these principles:
Compiler design
The rough design of the compile stage is to emit isolated CIL opcodes for each bytecode in the compiled frame.
Because of the flexibility of Python's type system, the opcodes will mimic CPython's eval loop:
There is some added complexity, because .NET CIL requires that the value stack is a LIFO stack, whereas CPython implements a value "stack" but actually uses it like an array.
The calling of the C API method is wrapped by the .NET
CEE_CALL
opcode, which calls a wrapper method implemented in theintrins.cpp
file.Without further optimizations, Pyjion would perform roughly the same as CPython (as fast or slow as the C API methods its calling).
The benefits of Pyjion come from changing the emitted machine code by deterministic observations about the inputs, constants or environment.
Beta Was this translation helpful? Give feedback.
All reactions