Talk

SPying the Future of Python Compilers: The Numba Example

Friday, May 29

16:25 - 16:55
RoomTortellini
LanguageEnglish
Audience levelAdvanced
Elevator pitch

SPy is a Python variant built for compilation: well-specified, debuggable, and expressive. It can run on its own, but because of its internal architecture is perfect as a frontend for all specialized compilers in the Python ecosystem, Numba being one practical example.

Abstract

In this talk we show how we integrated SPy with Numba: SPy acts as a frontend which handles the high-level Python constructs and emits a low-level AST, which Numba ingests to ultimately emit highly optimized code.

By leveraging SPy, Numba unlocks “for free” support for high-level constructs such as classes, decorators, operator overloading and the descriptor protocol. Moreover, large parts of logic which earlier needed to be written as compiler builtins such as numpy support, now can be written as normal SPy userland code.

This pattern is not specific to Numba but can be generalized to all specialized compilers which can compile a restricted subset of Python, usually with a focus on performance and targeting one or few use cases, e.g. by privileging numerical computation, AI, CPUs vs GPUs, etc.

Typically the specialized Python compiler development experience is not great. Each compiler supports a slightly different subset of Python, the exact restrictions and rules are usually vaguely specified and poorly documented, it may happen that the code has slightly different behavior when compiled and interpreted, and often bugs result in segfaults and (gdb) prompts.

SPy solves all these problems: it’s a dialect of Python which is designed from the ground up to be compilable, well specified, with a focus on development experience and debuggability. It supports a much bigger subset than the usual specialized compilers: it lowers high-level object-oriented constructs into low-level procedural representations that optimizing numerical compilers can readily process (e.g., C-like code). This enables users to write in familiar class-based designs with operator overloading, while the optimizing backend receives a version where abstractions have been eliminated or precomputed and can focus on numerical optimizations.

TagsCompiler and Interpreters, Performance and scalability techniques, Code Analysis and Typing
Participant

Antonio Cuni

Principal Software Engineer at Anaconda. He is the author of SPy, a core developer of PyScript and PyPy, and one of the founders of the HPy project, which aims to design a better and more modern C API for Python. He loves to write tools from developers for developers, such as Pdb++, fancycompleter and vmprof and he is creator/maintainer/contributor of numerous other open source projects.

He have also been very active in the Python community for years, giving talks at various conferences such as EuroPython, EuroSciPy, PyCon Italia, and many others. He regularly writes on the PyPy blog and on the HPy blog. His main areas of interest are compilers, language implementation, TDD and performance.