Note
Pylang is in an early development stage. Expect frequent errors, crashes, and poor performance. Please avoid using it in any projects.
Pylang is a Python code optimizer based on Abstract Syntax Tree (AST) that performs static analysis to improve code efficiency. It is designed to allow Python developers to write clean, maintainable code while benefiting from optimizations that reduce runtime overhead.
- Constant Folding: Evaluate constant expressions at compile time to reduce runtime calculations.
- Loop Unfolding: Unroll loops to reduce overhead, improving performance for certain scenarios.
- Unused Variable Remover: Automatically remove unused variables to clean up code and reduce memory usage.
- Variable Inlining: Automatically inline variables where applicable for improved performance.
- Advanced Decorators: Add support for decorators like
@inline
,@const
, and@native
for advanced optimizations. - Releases: Packaging the project with proper release notes and binaries for easier distribution.
- Documentation: Detailed API documentation and examples to guide developers in integrating Pylang into their projects.
- Clone the repository:
git clone https://github.com/xia-mc/Pylang.git
- Install dependencies:
pip install -r requirements.txt
- Run the optimizer on your Python project (Python 3.7+ require):
python Pylang.py <flags>
- F /D : Path to the file to be optimized.
- O : Path to the output folder.
- O0/O1/O2/O3: Optimize level.
- O0: Only format codes to make smaller.
- O1: Do some simple derivations and the functionality of the program will not be affected.
- O2: Do more aggressive optimizations, the behavior of certain functions (like exec) may change.
- tofile: Write logs to
latest.log
instead of printing to stdout. example:
python ./src/main/Pylang.py -D ./src/test -O2
Feel free to submit issues, pull requests, or feature requests to help improve Pylang. Contributions and feedback are greatly appreciated!
This project would not have been possible without the help of the following tools and platforms: