Execution speed is a key performance metric in many software applications, especially where computationally-intensive numerical calculations are involved. The core Python interpreter is often far too slow for practical numerical computation, and thus numerous projects have emerged over the past decades to enable faster execution. Some encapsulate a set of numerical computations in compiled extension modules (NumPy, SciPy, Pandas, Polars), some enable just-in-time compilation of Python code (PyPy, Numba, TorchDynamo, Pyjion, Pyston), and some provide ahead-of-time compilation (Cython, Pythran, Numba, Codon, Nuitka). Each of these types of Python acceleration tools has its strengths and weaknesses, and each is better suited for some applications than others.
LPython is a novel ahead-of-time compiler for a subset of the Python language that can be optimized using type-annotated Python code for multiple backends, including LLVM, C, C++, and WASM. It is a companion project to LFortran, a compiler that similarly optimizes Fortran code for these same backends. The main motivation behind LPython is to achieve maximum performance (not worse than C++ or Fortran). A key further motivation for both LFortran and LPython is ease of translation of code to the various backends, achieved through the use of a common, language-agnostic intermediate representation called the “Abstract Semantic Representation (ASR).” In theory, numerical code written in any language can be transformed into ASR, and from there into any supported backend. Thus, the ASR has the potential to be a “common path” for numerical code written in a variety of languages to be converted into an optimized form.
In this talk, Ondřej Čertík, lead LPython maintainer, demonstrates the performance capabilities of LPython through benchmarks against Numba and C++. He also delves into the internal workings of the compiler, explaining how it translates Python code into machine-specific instructions via the ASR intermediate representation. Ondřej shows a live demo of LPython and discusses future plans for the project.
LPython: https://lpython.org/
LFortran: https://lfortran.org/
LCompilers @ GitHub: https://github.com/lcompilers
Ondřej’s personal site: https://ondrejcertik.com/
Ondřej @ GitHub: https://github.com/certik
Ondřej @ LinkedIn: https://www.linkedin.com/in/ond%C5%99ej-%C4%8Dert%C3%ADk-064b355b/
August 15, 2023