Improving performance of Python code using rewriting rules technique
Autor: | Kostiantyn Zhereb |
---|---|
Rok vydání: | 2020 |
Předmět: |
020203 distributed computing
021103 operations research Parsing Computer science Programming language 0211 other engineering and technologies 02 engineering and technology Python (programming language) computer.software_genre Data type Code transformation 0202 electrical engineering electronic engineering information engineering Compiler Rewriting Algebraic number computer Compiled language computer.programming_language |
Zdroj: | PROBLEMS IN PROGRAMMING. :115-125 |
ISSN: | 1727-4907 |
DOI: | 10.15407/pp2020.02-03.115 |
Popis: | Python is a popular programming language used in many areas, but its performance is significantly lower than many compiled languages. We propose an approach to increasing performance of Python code by transforming fragments of code to more efficient languages such as Cython and C++. We use high-level algebraic models and rewriting rules technique for semi-automated code transformation. Performance-critical fragments of code are transformed into a low-level syntax model using Python parser. Then this low-level model is further transformed into a high-level algebraic model that is language-independent and easier to work with. The transformation is automated using rewriting rules implemented in Termware system. We also improve the constructed high-level model by deducing additional information such as data types and constraints. From this enhanced high-level model of code we generate equivalent fragments of code using code generators for Cython and C++ languages. Cython code is seamlessly integrated with Python code, and for C++ code we generate a small utility file in Cython that also integrates this code with Python. This way, the bulk of program code can stay in Python and benefit from its facilities, but performance-critical fragments of code are transformed into more efficient equivalents, improving the performance of resulting program. Comparison of execution times between initial version of Python code, different versions of transformed code and using automatic tools such as Cython compiler and PyPy demonstrates the benefits of our approach – we have achieved performance gains of over 50x compared to the initial version written in Python, and over 2x compared to the best automatic tool we have tested. Problems in programming 2020; 2-3: 115-125 |
Databáze: | OpenAIRE |
Externí odkaz: |