My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
HowItWorks  
Updated Feb 18, 2011 by m...@hotpy.org

All Python source code is compiled into ByteCode which is executed by the virtual machine.

The running virtual machine monitors certain points in the code; backwards jumps and the entry point to functions. If any of these is run more than 10 or 20 times, it becomes "warm" which means that HotPy will start optimising the bytecode.

The majority of the optimisers in HotPy are bytecode-to-bytecode transformations This bytecode-to-bytecode optimisation proceeds in four stages:

  • Tracing which records a sequence of bytecodes to be passed to the other optimisation passes.
  • Specialisation which specialises the code according to the types of objects observed during the tracing phase
  • Deferred Object Creation This is a form of escape analysis that delays creating small short lived objects such as tuples and dicts for parameters, frames and slices until required, which is often never.
  • Peephole optimisation cleans up the resulting code, by replacing short sequences of loads, stores and stack manipulations with more efficient alternatives.

The final phase in optimisation occurs when an optimised trace has been run several hundreds or thousands of times and becomes "hot". The trace is then compiled into machine code.


Sign in to add a comment
Powered by Google Project Hosting