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 hope this translates into further speed ups for EVE online down the road.
What if Oprah's ass got 5x's smaller?
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
It would still be huge! :-)
Sleep your way to a whiter smile...date a dentist!
While you're at it, what is the capitol of Assyria?
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.
0.5x slower is like 2x faster, right? Reciprocals?
Parrot's a lot harder to use to interact with other languages. LLVM at least makes it possible for Python code to play nicely with C compiled via LLVM, for example.
"You can either have software quality or you can have pointer arithmetic, but you cannot have both at the same time."
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?
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.
Mod up
Slashdot's rate-of-post filter: Preventing you from posting too many great ideas at once.
Parrot's a lot harder to use to interact with other languages.
Uhh... wha? That's one of the entire reasons Parrot exists. Any language that's compiled to Parrot can interact with any other language compiled to Parrot.
LLVM at least makes it possible for Python code to play nicely with C compiled via LLVM, for example.
Huh? I *really* don't see how LLVM provides a mechanism for languages to interact with one another. It's IR is really just machine code, it's just that the machine doesn't actually exist. In that sense, compiling to LLVM IR is absolutely no different than compiling directly to, say, x86, and it's pretty clear that Perl, compiled to x86, can't interact with Python, compiled to x86, so why would that be any different for Perl compiled to LLVM IR and Python compiled to LLVM IR?
Remember, language interaction requires a whole host of things, including a common underlying framework for how objects are represented, how methods are called, etc. As far as I know, LLVM provides none of that (unlike the JVM, CLR and Parrot). Heck, it only offers a few types of primitives, including basic numbers, pointers, and lists. It has no concept of objects at all... so how is a Python object supports to interact with a Perl object, for example?
That said, you could certainly build something like that *on top* of LLVM (eg, a CLR, JVM, or Parrot backend that compiled down to LLVM IR, which then provides the necessary infrastructure for languages to interact), but LLVM itself does not, as far as I can tell, directly facilitate such a thing.
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."
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?
Yes. If you didn't know all of that was going to happen, you're prototyping. If you're prototyping, you should be doing it in a prototyping language.
Rewriting from Python to C++ is not particularly difficult. Completely overhauling the design of a project written entirely in C++ is really unpleasant and takes a long time. So much so that many early design decisions on large C++ projects simply cannot be undone.
Model in clay first, then in stone later if you have to.
"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.
Since it is not going to be rewritten because of time, budget, it's good enough, [insert-your-own-excuse-here], let's opt to write it correctly and in an appropriate language from the onset.
If they're going to do a half-baked job in Python, then it would be tenth-baked in C. And if Python's performance is universally unacceptable today, I'm curious as to how you think we accomplished anything at all 10 years ago.
How to solve most of our problems: 1.Lots of nuclear plants. 2.Cure aging.
Not even the crow beats station-spinning the Orca.
- These characters were randomly selected.
Here's your cookie:
\_/
Nerd rage is the funniest rage.
:confused:
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 is stable and in use. The iPhone SDK arm compilers use gcc with a llvm backend. OS X uses LLVM in the OpenGL stack to support features that the GPU doesn't. They're also using LLVM for openCL/Grand Central.
LLVM isn't just another virtual machine, it also optimizes that code (at compile time, link time, and/or runtime) and converts it to native (alpha, arm, cell, ia64, mips, CIL, pic16, ppc, sparc, x86) binaries (or C source code).
Do you even lift?
These aren't the 'roids you're looking for.
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."
Goddammit! The next one of you fullatos that adds a number to another number is gonna hear it from my .45.
After all, I am strangely colored.
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.
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.
Then what? Rewrite?
Then you profile your code to see where the bottlenecks are and implement the bottlenecks in C, leaving 99% of your code unchanged, but getting 99% of the speed you'd get if you rewrote the whole thing in C.
Sounds like win-win to me.
If you really need that extra 1%, use some of the money you saved on development time and purchase a faster machine.
*sigh* back to work...
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.
I haven't looked at LLVM, but I think you need to learn about static single assignment (SSA).
I'm fully aware what SSA is. They model SSA using a set of write-only registers, but that doesn't change the fact that the dataflow is modeled using a machine language that is RISC-like in architecture.
There doesn't have to be any conflict between the two: lots of SSA intermediate representations look like RISC.
I completely agree. But I never claimed there was such a conflict.
then you are also confused (and egregiously confusing your readers) when you describe its registers as being "write-only"
No, I'm specifically correct about them being write-only, and they're write-only specifically because they're using SSA to facilitate certain optimizations, as it makes dataflow analysis a *lot* easier.