Project Aims For 5x Increase In Python Performance
cocoanaut writes "A new project launched by Google's Python engineers could make the popular programming language five times faster. The project, which is called Unladen Swallow, seeks to replace the Python interpreter's virtual machine with a new just-in-time (JIT) compilation engine that is built on LLVM. The first milestone release, which was announced at PyCon, already offers a 15-25% performance increase over the standard CPython implementation. The source code is available from the Google Code web site."
I like the clever name, but what is 5 pounds off of Oprah's ass? It's still huge!
I hope this translates into further speed ups for EVE online down the road.
The summary misses one of the best bits -- the project will try to get rid of the Global Interpreter Lock that interferes so much with multithreading.
Also, it's based on v2.6, which they are hoping will make 3.x an easy change.
They say five times faster however it really depends on if they're talking about a European or African Python Interpreter.
I read about what they intend to do, and they seem to have quite a few interesting ideas... But there are also major drawbacks:
- No Windows support (apparently a Linux-only VM in the plans)
- No Python 3.0 support
And thus no guarantees most of the work will merge back into CPython.
But competition is good, I can't really see a problem with having an alternative faster Python runtime, even if it's not as compatible as CPython. :)
.: Max Romantschuk
Because 24 is the biggest number there is. That's alls I'm sayin'. Forget about it.
There's no -1 for "I don't get it."
While you're at it, what is the capitol of Assyria?
The Parrot project's VM (mostly oriented towards Perl 6) would be a much better target, especially since work on that dynamic language register-based virtual machine has already been going on for some time, even for Python.
Or BSD, or several other important platforms.
---- Booth was a patriot ----
FTFA:
Adopting LLVM could also potentially open the door for more seamlessly integrating other languages with Python code, because the underlying LLVM intermediate representation is largely language-neutral.
So much for Parrot.
In the course of every project, it will become necessary to shoot the scientists and begin production.
3 times faster?
0.5x slower is like 2x faster, right? Reciprocals?
Because 42 is the only number there is.
Multiplicative changes mean nothing when dealing with things like zero and infinity.
In this case, there's just no escape: you still have a black hole.
(tempting fate on that whole existence-of-Hell thing)
Word has it that Microsoft created a speedy IronPython implementation on their Common Language Runtime and JIT technology for .NET.
Here are benchmarks for it.
Failing to find similar benchmarks for comparison; can anybody else contribute to this info?...
It sounds like that they're going to take Python, which is already gets translated to some kind of p-code (right?) and either translate the original Python or the p-code into LLVM code, which is then JIT-compiled to the native architecture.
The translation from Python to LLVM is going to lose some specificity and require that extra code be added to implement whatever needs to be done in Python that isn't trivially implemented by LLVM. Then the LLVM code needs to be compiled to native, introducing yet more "glue" code in the process.
Wouldn't a more direct compile yield a better result?
And don't give me any junk about compiling dynamic languages. LISP and Self are highly dynamic languages, yet they're compiled. If they can be compiled, then so can Python. I mean, the fact that it can be done through multiple levels of translation proves that it can be done, although possibly inefficiently. I just think that a more direct approach would reduce some of the superfluous glue code and a variety of other inefficiencies in translation that result from a loss of knowledge about what the original program was actually trying to implement.
I get emails claiming to increase my python's performance all of the time, I just delete them.
One of our competitors trademarked the term "hypothesis". From now on, we will call them "boneheaded ideas".
Is there any hope that we will move away from these boutique programming languages and back to "real languages" that seriously consider size and performance?
I for one am completely sick and tired of 3Ghz multicore processor machines with gigabytes of RAM running like a 486. Languages like Python don;t help in the bloat arena and the scripting languages made out of frameworks on top of other scripting languages are just ludicrous!
I do my best here not to offend, but I can see clearly now why I don't use Python.
I keep getting pressured by others to adopt it rather than my C or C++ but if they are touting a possible 5x increase, that means it was really, really slow to begin with. And how much further is there to go? I suspect it is not even worth benchmarking it yet.
Since all I mostly do is big matrix and vector work why would I use python? And no, scipy doesn't count as I can get MPI going pretty quickly.
Yes, I realise the right tool for the job argument.
.
So whatever happened to 'Stackless' Python? Is that ever going to be merged into CPython? And would it work with this?
It is not a project by Google's engineers, it's an independent project hosted by Google.
Also, 5x speedup is insignificant. Psyco already provides speedups much larger than that, depending on the type of code (algorithmic code could be improved 60x or more).
By the way, Pypy is much more ambitious than this one.
And finally, their goals and timeframe seem a little bit unrealistic. I'd love to be proved wrong though...
One can write a GUI in Python. With enough effort, it may even be usable for light tasks, at least with an Intel Core i7 or similar. In other words, it's kind of like JavaScript, but not as fast.
They (http://morepypy.blogspot.com/) have noticed the project, it seems.
We were a bit confused about usage of the term JIT, because as far as we understood, it's going to be upfront compilation into LLVM. In the past we have looked into LLVM - at one point PyPy extensively use it but it wasn't clear how we could make good use to it.
They seem a bit sceptical.
You're not CPU bound until you: add all the features, handle the special cases, add the error checking, scale up beyond trivial test data, etc.
Then what? Rewrite?
It's way better to simply avoid going down that path. If you start your project with Python, soon enough you'll hit trouble. If all your skills and personal library of code is Python, it's not reasonable to escape.
If you start in C, you know your performance will never really be limited by the language.
My head is already spinning when I hit the MWD so no further speedups please! Also, get out of Jita etc.
I find Python is about 20x slower (and about 10x faster to implement) than C, with the number varying quite a bit depending on how CPU-bound the code is. Given the speed of modern processors, this is plenty fast for many tasks.
Beyond that, many Python programmers employ a strategy of writing just the CPU-intensive inner loops in C or C++. This gives you most of the speed of an all-compiled solution but with much of the easier programming (and shorter programs) of the all-Python approach.
My particular scientific application runs on 1500 cores, is about 75% Python/25% C++, is 4-5x smaller than similar all-C/C++ programs, and runs at about 95-99.99% of the speed of an all C++ solution.
(Somewhat ironically, some of the worst performance bottlenecks in this app had to do with the overhead of some of the STL containers, which I ended up having to replace with C-style arrays, etc. to get best performance.)
Not all apps will fall out this way, but you definitely can't assume that just because something's written in Python that it will be slow.
(Going beyond that, we all know that better algorithms usually trump all of this anyway. If writing in Python gives you the time and clarity to be able to use an O(n)-better algorithm, that may pay off in itself.)
"Not an actor, but he plays one on TV."
Nineveh then, Baghdad now.
Porting python to LLVM will be a quite ambitious step with lots of work. I suppose they'll end up with a virtual machine having similiar performance characteristics to Jython/IronPython without overhead of Java/.NET/Java_programming_style. It will be suitable for server environments and this is what Google is paying for ;)
The fascinating thing about the LLVM architecture is that you can bolt any language on the front end, and still benefit from a mountain of hardware-specific optimizations on the back end, without the need to figure them out and implement them yourself. Erlang, D, and Occam front ends for LLVM are just some code away... just a shout away, just a kiss away... kiss away... kiss away, hey, hey-ya...
If you mod me down, I shall become more powerful than you could possibly imagine.
It is not a project by Google's engineers, it's an independent project hosted by Google.
The project is indeed sponsored by Google. See the last question in their FAQ.
Also, 5x speedup is insignificant. Psyco already provides speedups much larger than that, depending on the type of code (algorithmic code could be improved 60x or more).
You're saying it yourself: depending on the type of code. Psycho may achieve impressive speedups for certain algorithms, but the gains are not has high in general. These guys are aiming at speeding all Python code up by a factor of about five, which would be far from insignificant if they suceeded.
By the way, Pypy is much more ambitious than this one.
Pypy is an interesting project. Unfortunately, though, they are progressing very slowly.
And finally, their goals and timeframe seem a little bit unrealistic. I'd love to be proved wrong though...
You may be right here. Only time will tell.
i submitted this story to slashdot before anyone yesterday
i submitted this story yesterday but obviously i didn't do it right
You are right. I read it again and it seems the project is lead by two Google engineers working full time, plus the collaboration of other googlers on their 20% free time. However, Google doesn't own the project, they simply sponsor it.
As for the intended speedups, I'm still confussed. Psyco gets typically 4x speedup for common code, and shines when the code is cpu intensive (being theoretically on par with c).
So making such a big effort to get, again, a similar speedup is nonsense...
Psyco only runs on x86, this project will (ostensibly) run anywhere LLVM runs.
Nerd rage is the funniest rage.
This is disappointing. Shed Skin has shown speed improvements of 2 to 220x over CPython. Going for 5x over CPython is lame. But Shed Skin is a tiny effort, and needs help.
PyPy got a lot of press, but they tried to do an optimizing compiler with "agile programming" and "sprints", and, at six years on with substantial funding, it's still not done.
The fundamental problem with running Python fast is its gratuitous dynamism. In CPython, almost everything is late-bound, and most of the time goes into name lookups. This makes it easy to treat everything as dynamic. You can store into the local variables of a function from outside the function, for example. In order to make Python go fast, the compiler has to be able to detect the 99.99% of the time when that isn't happening and generate pre-bound code accordingly.
Dynamic typing requires similar handling. Most variables never change type. Recognizing int and float variables that will never contain anything else creates a significant speedup. In CPython, all numbers are "boxed", stored in an object structure. This is general but slow.
CPython is nice and simple, but slow. Serious speedup requires global analysis of the program to detect the hard cases and generate fast code for the easy ones. Shed Skin actually does this, but has to place some limitations on the language to do it. If someone did everything right, Python could probably achieve the speed of C++.
There's also the problem that if you want to be compatible with existing C modules for CPython, you're stuck with CPython's overly general internal representation.
LLVM has it's own active sub project for higher level languages ... they just released an OCaml compiler in fact (easier than Python of course, since it is statically typed).
Kramulous: Where's a good place to learn about this stuff?
"Not an actor, but he plays one on TV."
Shylock (not a lender of money, but a plastic surgeon): I will have my 5 pounds of butt flesh!
Stedmann: (As lawyer representing Oprah). Be my guest. It won't even be missed!
Now your developers must be good at both Python and C++. Note that I don't mean merely "able", because any decent hacker can pick up a new language in two weeks or less. Shallow ability won't really do the job. Getting good at a language takes years of experience.
At every point in time, the rewrite will seem like a much more task than fixing up the Python. You think things like: "just a little bit of optimization and this is going to be acceptable". It's not easy to commit to the rewrite, even if you know you need it.
BTW, completely overhauling the design of a project written entirely in C isn't so bad. You don't get the ravioli classes problem that most C++ code suffers from.
Project Aims For 5x Increase In Python Performance
Everyone should learn the Truths of Software Engineering from some source. For some people, it's The Daily WTF. For me, it was the Ultima series developer quotes. This time, the appropriate quote comes from Ultima VIII:
"It's hypothetical, or I'm going to poke you in the eye." - Rob to Tony when Tony describes possible 20 percent increase in game speed.
But don't expect it any time soon.
Indeed. Most of my Apple Basic software running on a 1 MHz 6502 was damn fast. In some important ways scripted code is often much faster. If you want to change a line of C++ code: "I'll have to change a line of code. Oh no, I'll have to wait several minutes to relink correctly, then I'll have restart the App and get it back to this point". In scripted code: "Changes line of code. Hits retry."
The experimental combination of the Python-to-Javascript compiler, http://pyjs.org/ and the Python Bindings to Google's V8 Engine, http://code.google.com/p/pyv8 brings a ten times performance increase over standard python, already.
not - "10% now and 5x in the future" - that's a 1000% increase NOW.
When V8 supports the ECMAScript "Harmony" standard, which will include support for basic integer types, then there will be "correct" support in the PyJS + PyV8 combination for numerical types, and the word "experimental" can be dropped.
http://pyjsorg/ also includes an experiment showing the bindings of the PyJS compiler with the Python-Spidermonkey project. The spidermonkey JS engine has the advantage of running on generic platforms instead of just ARM and 32-bit x86 platforms, but has the disadvantage of being slightly slower.
Javascript is a _really_ interesting language that makes it in many ways highly suitable as an intermediate compiler language for compiling dynamic languages as Ruby and Python.
Great minds think alike! The Parrot team is already working on using LLVM for JIT code generation.
For once, I disagree with Ars Technica. In Python, integers automagically overflow into "long integers" (ie., BigNums). Therefore you can only compile integer operations into low-level opcodes (x86, LLVM, etc) if you somehow know beforehand that the no BigNums are involved and overflow is impossible. In general, you have to compile Python into calls on a python-specific run-time library instead of opcodes. (You can still produce code that runs much faster than CPython's stack-based bytecodes by using a register-based VM and by pushing type-based dispatch as early as possible.)
IMO, trying to generate language-neutral machine/LLVM code is a bad idea. The Parrot team seem to agree: Parrot byte-code will strongly reflect the source language; their aim is not language-neutrality but inter-language operability.
If julesh is right about LLVM being SSA, then you are also confused (and egregiously confusing your readers) when you describe its registers as being "write-only": SSA registers are always write-once. There is a lot of overlap between SSA and functional programming.