Spherical forums

General Discussion => Off-Topic Discussions => Topic started by: Flying Jester on August 02, 2014, 04:58:16 am

Title: TurboFan: Google V8's new Compiler
Post by: Flying Jester on August 02, 2014, 04:58:16 am
I call shenanigans on that name. I was using the word "Turbo" in conjunction with V8 long before Google ever did! And, what, they're relating a component of a car's engine to a style of jet engine? That makes less sense than calling the compiler a crankshaft!

https://translate.google.com/translate?sl=auto&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Fwww.golem.de%2Fnews%2Fturbofan-googles-neuer-v8-compiler-fuer-chrome-1408-108291.html&edit-text=&act=url (https://translate.google.com/translate?sl=auto&tl=en&js=y&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Fwww.golem.de%2Fnews%2Fturbofan-googles-neuer-v8-compiler-fuer-chrome-1408-108291.html&edit-text=&act=url)

https://codereview.chromium.org/426233002 (https://codereview.chromium.org/426233002)

https://groups.google.com/forum/#!msg/v8-dev/ab8V5Z58_70/5-05DvysCt8J (https://groups.google.com/forum/#!msg/v8-dev/ab8V5Z58_70/5-05DvysCt8J)

This literally just landed in the Chromium branch of V8 a day ago, so that's the only source I can find that describes it. But someone I know at Mozilla says that this patch finally makes V8 faster than SpiderMonkey again. A long time ago, I said that I had faith that V8 would remain faster than SM. For about the last year, it was the other way around.

I did a tiny bit of profiling, and I think I see why TurboFan is so much better. V8's old high optimizer (Lithium? Or was it Hydrogen?) In Crankshaft had a really hard time spinning up--it would take thousands of loop runs, tens of thousands of function calls, sometimes it would spin up and down without reaching equilibrium. It seemed that the old compiler's optimizer was petrified of making an optimization that would need to be reversed. Newer SM does the opposite, optimizing after as few as ten loops or calls. And it seemed to pay off! I think that TurboFan has new optimizer (or perhaps just provides better info to the same old optimizer?), either way it spins up way faster and more consistently.

It also looks like TurboFan can compile to true 64-bit machine code, which is something V8 didn't do before! I'm excited to see this in action!
Title: Re: TurboFan: Google V8's new Compiler
Post by: Fat Cerberus on August 02, 2014, 12:54:04 pm
A jet engine?  I'm confused now.  V8 is a type of car engine, and car engines contain fans (well technically I guess the radiator does).  No mixed metaphor here.
Title: Re: TurboFan: Google V8's new Compiler
Post by: Flying Jester on August 02, 2014, 03:42:54 pm
A TurboFan in particular is a type of jet engine. http://en.wikipedia.org/wiki/Turbofan (http://en.wikipedia.org/wiki/Turbofan)
Title: Re: TurboFan: Google V8's new Compiler
Post by: Radnen on August 02, 2014, 04:02:42 pm
Man you got access to some bleeding edge stuff there, I can't even find references to turbofan when searching for it. Only a few sentences here and there. I guess they are waiting to go public with this, it still looks a ways off.

I'm surprised a lot of interest was built around a code commit. Haha, looks like the gauntlet was thrown.
Title: Re: TurboFan: Google V8's new Compiler
Post by: Fat Cerberus on August 02, 2014, 10:51:07 pm

[...] this patch finally makes V8 faster than SpiderMonkey again. A long time ago, I said that I had faith that V8 would remain faster than SM. For about the last year, it was the other way around.


Wait, when did SpiderMonkey get faster than V8?  I thought V8 was always faster, guess I've been out of the loop...
Title: Re: TurboFan: Google V8's new Compiler
Post by: Flying Jester on August 03, 2014, 01:09:10 am
There's a lot of hype around that one commit because the whole thing was created in secret, and then all committed in one go.

SpiderMonkey got faster about a year ago, when OdinMonkey (?) landed.

Basically, they replaced TraceMonkey with a new low optimizer (OdinMonkey) that has one goal: provide the best type information possible to the high optimizer. The thing is, when V8's high optimizer kicked in, it was miles ahead of SpiderMonkey. It just had a really hard time kicking in. So even though JaegerMonkey (the high optimizer) and IonMonkey (which inlines machine code) are kind of worse than V8's Lithium (which produces more efficient machine code), they were kicking in much more often and with better info going in (which helped them reach equilibrium much more reliably). So in actual use, especially in medium-lived functions (more than 10 runs, less than 10,000), SpiderMonkey was kicking V8's butt. In very long lived scripts, it was mostly a question of whether Lithium could stay spun up. If it could, V8 stayed faster. When it couldn't, V8 was very slow.

The thing is, not that many functions that run a ton of times are difficult to optimize (a case where Lithium could outdo JaegerMonkey), so V8 had a very difficult time flexing its muscles.

I'm actually kind of curious if TurboFan is a new high or low optimizer--is it replacing Hydrogen, letting Lithium spin up faster and with better info, or is taking the place of Lithium and staying spun up more reliably? Or is it just faster than Lithium? I kind of doubt that, given that Lithium, when it spins up and stays engaged, is one of the fastest JITs--if not the fastest--around.
Title: Re: TurboFan: Google V8's new Compiler
Post by: mezzoEmrys on August 06, 2014, 11:29:36 pm
Hearing all the highs and lows of these makes me wish we could just grab the bits and pieces, the low optimizer and the high optimizer and all that, and just connect them for the best of both worlds. Sadly that plan obviously won't work for a multitude of reasons.
Title: Re: TurboFan: Google V8's new Compiler
Post by: Flying Jester on August 07, 2014, 02:01:12 am
The reason why that won't work is precisely why SpiderMonkey become powerful, using Baseline and IonMonkey. The best JIT is the one that has a very well integrated set of compilers and tracers. It can provide good information to a high optimizer, and the high optimizer can graceful back down when it needs to.

Of course, mixing and matching JITs in a fantasy JIT league is pretty fun :D