Ars Technica: Firefox to get massive JavaScript performance boost.

Mozilla Blog: What can you do when your browser is 7 times faster?.

The technology behind these speedups is trace-based optimization, a method of performance prediction that can use the information about which parts of some code have been important already to concentrate compiler-optimization power on making the same code run faster the next time. The researchers behind this are UCI computer scientist Michael Franz and his post-doc Andreas Gal.

Personally, I'm not so thrilled about JavaScript, despite my browser using it all the time on various web sites. But I'm interested in this for another reason: I do a lot of my programming in Python, and sometimes when I do I feel like I need to apologize for Python's poor performance compared to C. But this technology should work just as well in Python as in JavaScript, and gives me hope that eventually my Python code will be as fast as if I had taken the extra effort to write in a compiled and optimized language.





Comments:

brooksmoses:
2008-08-23T08:14:00Z

Just as fast, or faster. One of my former coworkers ended up working on this when he left us for Mozilla, and he was telling me about it. Apparently some of the early work on this was done with hardware emulators -- and they found that the emulator, when running on the machine it was emulating, sometimes ran faster than the native code once it had collected enough traces.

It sounds like really neat stuff, in any case.

leonardo_m:
2008-08-23T10:23:24Z

7-times speedup is probably too much, the real speedup is about 1.5-4 on average programs, and 4-8 on number crunching programs.

There is already a system for Python that performs really similar things in a similar manner, it's Psyco (that will 'soon' have a major upgrade).

If you want your Python code to run quite fast you may try ShedSkin.

None: Let us not get ahead of ourselves!
2008-08-23T12:17:39Z

There is no question that Python can be made to run very fast. If you use it like I do, and write the core parts in C++ and then use SWIG to wrap your C++, then you get to use Python with a C++ performance, right now.

Also, if you want to benefit from a sophisticated JIT compiler right now, try Jython. I bet a lot of your code runs unchanged on Jython (hint: it will use the Java JIT compiler!).

Ok, but how fast can JavaScript and Python get compared to compiled languages? Well, there are typically 1000x slower. So, can you boost their performance by a factor of 10 and be 100x slower? Sure.

In some corner cases, you can get to be only 10x slower. Or, you may even get to be *faster* in some instances.

People do not believe me, but back in 1999 I was writing image processing software, and on some operations, my Java code was faster than hand-crafted C++ code! Yet, nobody back in 1999 would take Java as an image processing library seriously. And they were right too!

You see, being faster in some tests is not too exciting. Over time, your non-trivial software will do a lot of wicked things... it is the overall performance that matters. Can JavaScript or Python match C++ in overall performance? I doubt it very much. I doubt it will ever happen.

Ah! But does it matter?

If you do wicked database research like I do, you often need ever little once of performance because you need to process gigabytes of data and run thousands of tests... even Java is not appropriate as a language in some cases.

However, 99.9% of software out there can afford to be 10x or even 100x slower than C++.

--
Daniel Lemire
http://www.daniel-lemire.com/

chouyu_31: Re: Let us not get ahead of ourselves!
2008-08-23T14:51:13Z

Python is rarely 1000x slower than C/C++. Raw numbers for most benchmarks (available from http://shootout.alioth.debian.org/gp4/benchmark.php?test=all&lang=python&lang2=gcc ) put it at single-digit, moderate double-digit, or rarely 100-300x slower than straight C. With a bit of Psyco, Python worst-case (in those same benchmarks) drops to 50x as slow, with many of the benchmarks showing low 1-digit slowdowns.

You may be right in the general case for Python/JavaScript to not be faster in the future than C/C++, but most C is also not any faster than Fortran, yet we made the transition anyways ;) .

leonardo_m: Re: Let us not get ahead of ourselves!
2008-08-23T18:46:42Z

For many programs Python is way less than 1000 times slower, it's more about 10-20 times slower. And Jython is generally quite slower than CPython, so it isn't a match for Psyco.