Programs written in the Python scripting language are compiled into bytecode and executed by an interpreter. Runtime performance is influenced by bytecode quality. This paper examines how bytecode transformations can improve bytecode quality. The transformations preprocess bytecode, using function inlining and loop unrolling to expose more code, and then apply dataflow optimizations, such as constant propagation and loop-invariant code motion.
Python is dynamically typed, making the traditional compiler-based static type analysis difficult; in addition, static analysis runs counter to Python’s interactive development style. This paper replaces static type analysis with filtering rules that dynamically identify code segments to which transformations can be safely applied. Loop unrolling is augmented with array index substitution, creating more opportunities for dataflow transformations after unrolling, such as replacing redundant array references with fast immediate variables.
Experiments show that the transformations provide spectacular improvements (100 to 1,000 percent) on benchmarks and microkernel code, and much more modest--but still good--improvements (20 to 30 percent) on difficult cryptographic code.
This paper requires a modest knowledge of either Python or language optimization. The general theory behind the transformations is described in detail, but no implementation details are presented or cited. The prose is awkward, using clumsy passive-voice constructions and sentences. The bibliography serves the paper, if not the large and rather haphazard field of scripting language optimization.