Main menu:

Site search

Categories

Archive

Crankshaft

The V8 team has dropped Crankshaft, a new JIT system for JavaScript, into their bleeding-edge repo. According to their blog entry, it doubles their speed on 3 of 8 V8 benchmarks, and improves page load time by 12% on JS-heavy pages.

First off: Congratulations to the V8 team. It looks like great work, pushing forward what kinds of things JS can do in the browser. I look forward to checking out the code.

Analysis. I haven’t looked into the details yet, but their blog post has a good summary and I can make some guesses based on my own knowledge of the subject. I think the key features are:

  • Dynamic recompilation. Crankshaft introduces an optimizing compiler that does complex optimizations, such as register allocation and loop-invariant code motion. These optimizations take time, so they would make startup slow if that was the only compiler. But Crankshaft also has a base compiler that starts fast but doesn’t optimize very much: probably less than the V8 compiler, in fact. Only if the code is predicted to run many times will it be compiled with full optimization.
  • Profile-driven type specialization. That means Crankshaft records the types of variables and the targets of function calls at runtime, and then recompiles methods specialized to those types and targets.

I have to point out that runtime type specialization for JavaScript was pioneered by Mozilla’s Tracemonkey project. It looks to me like Crankshaft adds three new things to the type specialization mix: (1) instead of recording a trace once and then doing type specialization, they profile over multiple iterations so they can gather more information, (2) compiling whole methods instead of linear traces, introducing a bit larger scope to the optimizations and reducing code size, and (3) using ICs along with type specialization.

Another indication that Crankshaft and Tracemonkey are fundamentally related: Crankshaft gets a big boost over V8 on the benchmarks deltablue, richards, and crypto. Tracemonkey gets a big boost over JaegerMonkey on deltablue, richards, and splay.

(Historical note: Most of the fundamentals of JIT optimization were established in the research language Self in the 80s and 90s. Subsequent work has typically focused on porting those techniques to new languages, adapting them to modern processors, and making various incremental improvements. In the 90s and 00s that was done with Java, which gave us our modern high-performance Java JITs. It looks like the 00s and 10s will see it done for JavaScript. It’ll be interesting to see how close JS perf gets to Java.)

Response. The Mozilla JavaScript team and developer community definitely have the skills and resources to enhance our dynamic type specialization system with ICs, more profiling data, wider compilation scope, and whatever else we can think of. So we won’t get left behind.

Also, we’ve already been working on static-analysis-driven type specialization. This means using static analysis to discover the types and targets ahead of time and then compiling with type specialization. The Self researchers found static and dynamic analysis to be about equally effective for optimization, but we won’t know whether that’s true for JS until we’ve tried it.

Brian Hackett created and implemented the type inference project, which is documented in bug 557407 and bug 608741. The code is in the JaegerMonkey repository. Brian is currently fixing bugs and integrating his work into the JaegerMonkey engine, and he already has some very promising performance results.

So, plenty to do after Firefox 4 comes out. In the words of David Anderson, “The game’s back on.”

Comments

Comment from Film İzle
Time: December 20, 2010, 5:32 am

Anyway, good job with the optimization I always love when things run faster!

Comment from plyometric workout
Time: December 20, 2010, 5:38 am

I was waiting for crankshaft for a long time. A much needed improvement.

Comment from christmas door decorations
Time: December 20, 2010, 5:39 am

Thanks for the article!

Comment from Schmuck Tipps
Time: December 20, 2010, 7:37 am

nice looking forward to seeing Crankshaft in action, will be nice to see how this effects the mozilla performance

Comment from Lauren D
Time: December 20, 2010, 8:46 am

Thanks for this info. I’m always open to learning more about javascript.

Comment from antiquefurniture
Time: December 20, 2010, 10:26 am

another javascript to be learn.that was cool.

Comment from Real Estate Longview
Time: December 20, 2010, 10:55 am

keep up the great work and teaching us about JavaScript.

Comment from Win real money playing online slots at Karamba.com
Time: December 20, 2010, 3:24 pm

Interesting blog, well worth a shot!. Thanks for great article. Great insights. I loved to read your article. Admiring the time and effort you put into your blog and detailed information you offer!

Comment from abenk
Time: December 20, 2010, 7:52 pm

it’s nice blog….. i like it..
pleased to meet your blog…
COME VISIT ME…OK…thank you very much.

Comment from molly
Time: December 20, 2010, 9:06 pm

Reading this i finally took a break from my job. This post just gave me a few minutes of relax =] I tried to find a rss feed on your site so that i could subscribe for some more. Ill be sure to come here more often from now on =]

Comment from FM Transmitter
Time: December 21, 2010, 4:40 am

Thank you for sharing. Good comments

Comment from depannage informatique
Time: December 21, 2010, 8:18 am

I didn’t know this about Javascript… i’m still learning but thx for this article, very interesting.

Comment from antivirus
Time: December 21, 2010, 8:19 am

Well article.. i just love Javascript 🙂

Comment from dating
Time: December 21, 2010, 8:26 am

sounds like a great feature. I’m still learning JS so I only really understood part of it but even so, great post!

Comment from church in richmond
Time: December 21, 2010, 9:45 am

we’ve already been working on static-analysis-driven type specialization. This means using static analysis to discover the types and targets ahead of time and then compiling with type specialization. The Self researchers found static and dynamic analysis to be about equally effective for optimization, but we won’t know whether that’s true for JS until we’ve tried it

Comment from GPS Mount
Time: December 21, 2010, 10:54 am

Thank you for the wonderful comments
i am trying to reach your email as I want to talk to you about advertisement but cannot.
Could you please write to me ?
Please

Comment from Car charger
Time: December 21, 2010, 11:23 am

I forgot to write my number which is 0044seven82521110seven
regards,
Edward

Comment from coffee substitute
Time: December 21, 2010, 3:13 pm

looks like a great feature. I’m still learning javascript so I only really understood part of it but even so, what a good article.

Pingback from Crankshaft
Time: December 22, 2010, 1:27 am

[…] speed on 3 of 8 V8 benchmarks, and improves page load time by 12% on JS-heavy pages. First off:… [full post] dmandelin David Mandelin's blog uncategorized 0 0 0 0 […]

Comment from Joanna from Man and Van
Time: December 22, 2010, 5:38 am

Very interesting new facts about JavaScript. Especially for a begging like me. Thanks!