Why Unladen Swallow is important to Python’s future

Unladen Swallow is a Google-led (but not Google owned) project that began earlier this year with the purpose of providing a compatible Python implementation that is at least 5 times faster than the current CPython implementation. Though it hasn’t really gotten a whole lot of attention (and is probably less well known than projects like Jython or IronRuby), it is still a very important project in its own right.

The CPython implementation currently works by compiling the Python source code for a custom virtual machine which then interprets them. Unladen Swallow’s basic approach is to replace the custom virtual machine and interpreter by a Just-in-time compilation strategy using the LLVM compiler infrastructure. The Python source code is compiled to bytecode which is then transformed to the LLVM intermediate representation. Any ‘hotspots’  in the code (functions called more than 1000 times) are then compiled by the LLVM JIT into native machine code and executed. This strategy makes the execution faster than with the bare custom VM approach. The 2009-Q2 release emits correct native machine code via the LLVM, but is not yet optimized for performance. As the 2nd quarter benchmarks show, significant progress has already been made, and as the JIT is further exploited and adapted more improvements are likely.

Even if the goal of Unladen Swallow were limited to just performance, that would be a big plus. Programs running on the Java Virtual Machine exploit its state-of-the-art JIT technology to allow long-running programs like servers and databases to gain considerable performance improvements. The various Python web frameworks like Twisted and Django would benefit from a JIT-based speedup. This in turn would make a Python an even more viable alternative in the web sphere. I personally think Python is a vastly superior alternative to Java and would love to see it be taken for more performance intensive projects.

However, the goal of Unladen Swallow isn’t just raw speed. If you look at the rest of the Project Plan you’ll see references to making more far-reaching changes to the Python internals. Simply using an LLVM-based backend opens up the possibility of having better inter-language cooperation, with added benefits of a native code generator. That would make it easier for programmers to combine their favorite programming languages to write a program while being able to ship a single, coherent binary.

Perhaps an even more exciting possibility is that of being able to do away with the infamous Global Interpreter Lock. The GIL is probably Python’s most well known necessary evil (with the possible exception of the whitespace thing, depending on who you ask). It enforces thread safety, keeping but at the cost of limiting the amount of concurrency that can be taken advantage of. As the number of cores per chip keep increasing, being able to use them efficiently will become a necessary part of any popular programming language. The aim for Unladen Swallow is to eventually remove the GIL entirely and implement a better garbage collection system based on work done at IBM.

Unladen Swallow is still a very experimental effort, but it is clearly a very serious project moving at a good pace with some very good people working on it. Eventually parts of it may be folded back into the core CPython implementation.  Google is already heavily invested in Python and as a result will certainly be making sure that the project comes to fruition and is sustained into the future. When Unladen Swallow does become production ready (I would say in a year or so at the most) it’s going to place Python as a powerful competitor in the industrial/infrastructure computing scene. As the changes become available to the general public, whether in the form of prebuilt binaries or source merges with CPython, it will make life better for Python programmers everywhere. Having a dynamic, flexible programming language which offers great performance to boot will make it easier for programmers to leave behind languages like C, C++ and even Java for a platform that makes application development smoother and faster. Here’s looking forward to the flight of the Unladen Swallow.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s