Pyston compiler cranks up Python thanks to LLVM

Dropbox's compiler for Python uses the LLVM to push the language closer to C/C++ speeds, but it's far from production-ready

Fast development or fast execution, take your pick. Python programmers elect to go with the former, but have always sought ways to make their choice of language run a little faster.

Pyston, a project from Dropbox, aims to address that trade-off. An open source (Apache-licensed) compiler for Python, Pyston uses the LLVM compiler infrastructure to run Python using just-in-time compilation, or JITing, a technique employed in the Java Virtual Machine. The newest iteration of Pyston, version 0.2, is still far from production-ready but is quickly taking shape.

Pyston was originally devised by a team of engineers at Dropbox whose stated goal was "to produce a high-performance Python implementation that can push Python into domains dominated by traditional systems languages like C++." The plan was to use LLVM to aid in this process. Apple's work using LLVM to speed up JavaScript comes to mind when searching for an example of LLVM accelerating other dynamic languages.

Dropbox's client-side applications are written in Python, and while Python's performance has traditionally trailed other languages, many developers find Python fast enough for many common applications that aren't computationally intensive. Plus, in many cases they're willing to trade the speedy execution of C++ or Java for the generally faster development iteration of Python. (Guido van Rossum, creator of Python, has made these points himself.)

The original version of Pyston merely laid the foundation as a way to get basic Python programs to compile with LLVM. Many features of Python were missing -- including support for Python's native C API, a way for Python to talk directly to C code and thus hand off functions that need to run at C's native speeds. Even that primitive version of Pyston was faster than the reference CPython implementation of the language, Pyston's developers claimed.

Version 0.2 of Pyston adds the C API, along with other new functions that bring Pyston a lot closer to being usable for production work (although that's still a ways off). Exceptions, inheritance and metaclasses, lambdas and closures, support for multithreading, and a slew of other Python-specific items are now working, according to the Pyston team.

One measure of progress is that as of version 0.2, many PyPy benchmarks can be run without modification. PyPy is another JIT-based compiler for Python that yields faster results -- sometimes by orders of magnitude -- than the reference Python implementation. Pyston works differently from PyPy, though, so many of the lessons learned with PyPy can't be mapped back onto making Pyston run faster.

The next step for Pyston, according to its developers, is to improve performance further: optimize the garbage collection methodology, get rid of its memory leaks, and on the whole make Pyston closer to working as a drop-in replacement for the existing generation of Python engines.

This story, "Pyston compiler cranks up Python thanks to LLVM," was originally published at InfoWorld.com. Get the first word on what the important tech news really means with the InfoWorld Tech Watch blog. For the latest developments in business technology news, follow InfoWorld.com on Twitter.

To comment on this article and other InfoWorld content, visit InfoWorld's LinkedIn page, Facebook page and Twitter stream.
From CIO: 8 Free Online Courses to Grow Your Tech Skills
Notice to our Readers
We're now using social media to take your comments and feedback. Learn more about this here.