AST Optimizers¶
Intro¶
An AST optimizer rewrites the Abstract Syntax Tree (AST) of a Python module to produce a more efficient code.
Currently in CPython 3.5, only basic optimizations are implemented by rewriting the bytecode: CPython peephole optimizer.
Old AST optimizer project¶
See old AST optimizer.
fatoptimizer¶
fatoptimizer project: AST
optimizer implementing multiple optimizations and can specialize functions
using guards of the fat
module.
pythran AST¶
pythran.analysis.PureFunctions of pythran project, depend on ArgumentEffects and GlobalEffects analysis: automatically detect pure functions.
PyPy AST optimizer¶
https://bitbucket.org/pypy/pypy/src/default/pypy/interpreter/astcompiler/optimize.py
Cython AST optimizer¶
https://mail.python.org/pipermail/python-dev/2012-August/121300.html
Links¶
CPython issues¶
- Issue #2181: optimize out local variables at end of function
- Issue #2499: Fold unary + and not on constants
- Issue #4264: Patch: optimize code to use LIST_APPEND instead of calling list.append
- Issue #7682: Optimisation of if with constant expression
- Issue #11549: Build-out an AST optimizer, moving some functionality out of the peephole optimizer
- Issue #17068: peephole optimization for constant strings
- Issue #17430: missed peephole optimization