7 ms·
V8: A Tale of TurboFan
- bhouston 10y agoVery interesting g.
- franciscop 10y agoThis is a huge deal for me. I am creating server[1] for Node.js: "npm install server". The slowest part I noticed in some initial benchmarks was the promise-based code which is used heavily instead of express' callback based middleware. While performance is not one of the main concerns for the library (they are simplicity, "batteries-on" and user experience in general) it is nice to see that my hunch was right; V8 would provide a 500% performance boost to Promises. [1] http://serverjs.io/ http://serverjs.io/
- davnicwil 10y agoI've never seen this before and it looks interesting - from a brief scan of the source & about section it looks to me like a wrapper over express to provide sensible defaults to round off some of the sharp corners when setting up a project from scratch. This could be extremely useful. I've been using express in production for years, and though setting up a new server is not fundamentally difficult, it does involve a lot of common boilerplate (cookie-parser et al) that I think a lot of people already solve with a boilerplate template. This could be a cleaner, more fully-featured approach. Is this more or less it, or is there more to it / future aims to do more? I also wonder - did you talk to the express developers about making direct contributions to provide solutions to these problems from within the express library itself, rather than externally via a wrapper library? I'll keep an eye on the development of this project :-)
- franciscop 10y agoThanks! I got started few months back. I haven't really talked to them besides asking a question or two. The thing is, express used to be like this but it was then split up; from what I read it was mainly due to unstability in the subpackages, something which I think/hope will be solved by now. Another point is apparently it's easier to maintain since there have been some problems internally. The main differences (for the initial or a later release) are: * A lot of functionality out-of-the-box. Just install it and get to work. * Websockets as first-class citizens: since they are one of the major advantages of Node.js in itself it makes sense they are trivial to use. * Error handling: intercept some messages from Node.js and provide a more human-readable version. * Promise-based. There's also a single parameter for middleware instead of a [err], req, res, next parameters, since Promises work really well with a single parameter. You might think that this comes from http://koajs.com/ http://koajs.com/ , but only the name comes from there, I used to call it inst for instance until I found a better name, which I found in Koa's ctx. Oh, I talk about all of this in here: https://serverjs.io/about https://serverjs.io/about
- mike_hearn 10y agoIt's interesting to watch the swings and roundabouts in the VM engineering space. I remember many years ago being in a Google engineering all hands where Android was first announced (to the firm) and the technical architecture was explained. I and quite a few others were very surprised to hear that they planned to take slow, limited mobile devices and run a Java bytecode interpreter on them. The stated rationale was also quite surprising: it was done to save memory. I remember being very dubious about the idea of running a GCd interpreted language on a mobile phone (I had J2ME experience!). In the years since I've seen Android go from interpreter, to interpreter+JIT, to AOT, to JIT+AOT, to interpreted + JIT then AOT at night. V8 has gone from only JIT (compile on first use) to multiple JITs to now, interpreter+single JIT. MS CLR still doesn't have any interpreter and is fully AOT or JIT depending on mode. HotSpot started interpreted, then gained a parallel fast JIT, then gained a parallel optimising JIT, then went to a tiered mechanism where code can be interpreted, compiled and recompiled multiple times before the system stabilises at peak performance. Looking back, it's apparent that Android's and indeed Java's initial design was really quite insightful. A tight bytecode interpreter isn't quite as awful as it sounds, especially given how far CPU core execution speed has raced ahead of memory and cache availability. If you can fit an interpreter almost entirely in icache, and pack a ton of logic into dense bytecode, and if you can use spare cores that would otherwise be idle (in desktop/mobile scenarios) to do profile guided optimisation, you can end up utilising machine resources more effectively than it might otherwise appear.
- pjmlp 10y agoThat was just catching up with what mainframes have been doing since the 60's. :) That is why when you research old papers about compilers, Assembly opcodes and Bytecode are often intermixed. It was common for the OS, language runtime to work with bytecodes, with the execution being done at microcode level. What nowadays would be better done as FPGA. On IBM i (aka OS/400), there is a kernel JIT and all languages target bytecode, including C. Also JVM bytecodes get translated into IBM I ones. It was implemented in PL/M, nowadays with many modules ported to C++. And if you want to generate actual machine code, you need the Metal C compilers. There are plenty of other examples. Like with containers, it is just recycling mainframe success stories.
- 10y ago
- rurban 10y agoSeeing all the problems and wrong assumptions they had, makes me appreciate luajit even more. 100x smaller, multiple times faster and did it right from the beginning.
- scriptproof 10y agoThat is irrelevant. On a typed and mostly static language all is 100x easier to compile too.
- throwawayish 10y agoJavaScript is typed as well.
- NiLSPACE 10y agoLua is a dynamic language though.
- scriptproof 10y agoYou are right. What is the magic formula to make the JIT so fast?
- pjako 10y agoJavascript has some features that makes it hard to be JITed. For example it has no fixed object layout. If you are interested into how language design impacts performance this is worth reading: http://wren.io/performance.html http://wren.io/performance.html
- readittwice 10y agoTo be fair it probably also helped that Lua is a simpler language and therefore easier to optimize. A tracing JIT also has an inherent downside: the infamous example of an if in an inner loop with roughly the same probability for the then and else branch. That said LuaJIT is an impressive piece of software. Would love to know what Mike Pall is up to now.
- dvdplm 10y agoLatest node (7.7.1) uses v8 5.5 I believe: does anyone know what the roadmap wrt to updating v8 to the latest version containing all this new stuff look like?
- pas 10y agoSince 16 days ago master uses 5.6, whereas v8 is at 5.8, the pull request took about a month to go through, but it touched ~2000 files, and there doesn't appear to be an open pull request for "update v8". So it seems it'll take some time (as it looks like a considerable effort). And current 5.7 issues seem to live here: https://github.com/nodejs/v8/issues https://github.com/nodejs/v8/issues https://github.com/nodejs/node/commit/7a77daf24344db7942e34c962b0f1ee729ab7af5 https://github.com/nodejs/node/commit/7a77daf24344db7942e34c... https://github.com/v8/v8/releases https://github.com/v8/v8/releases
- curveship 10y agoThere's a branch of node, vee-eight-lkgr, running the new v8 5.8 compiler chain. You can read about how to try it out (and help test it) here: https://medium.com/@bmeurer/help-us-test-the-future-of-node-js-6079900566f#.d2iq1i2zq https://medium.com/@bmeurer/help-us-test-the-future-of-node-...
- dvdplm 10y agoWorks great! On my project full builds went down from ~20s to ~17.5 and dev builds down from ~10s to ~7.8s! Good stuff. :)
- nicoburns 10y agoI think they're aiming to ship v8 5.8 with Node 8 in April.
- jules 10y ago> From my very personal point of view, the TurboFan optimizing compiler at that time was probably the most beautiful version we ever had, and the only version (of a JavaScript compiler) where I could imagine that a “sea of nodes” approach might make sense (although it was already showing its weakness at that time). What were the weaknesses of the Sea of Nodes? Backwards data flow analysis and control flow sensitive analysis being hard?
- qznc 10y agoI worked on a Sea of Nodes compiler [0] myself and "backwards data flow analysis and control flow sensitive analysis" has never been a problem. Changes to the CFG are hard because of the Phi nodes, which have to be adapted in lockstep with CFG changes. However, this is probably inherent to SSA form, but not sea of nodes. You want a good graph visualization instead of text-based output, because you should actually to see the "non-order of the sea". Text-output with an implicit order can hide issues. Personally, I believe sea of nodes is better then others, like SSA form is better than non-SSA. There is nothing which makes it inherently more powerful, but it feels more elegant. Unfortunately, there is no objective comparison and anecdotes are apples vs oranges. Similarly, how would you compare object-oriented with functional programming? [0] http://libfirm.org http://libfirm.org
- jules 10y agoLibFIRM's sea of nodes representation is a bit different in that nodes are tied to a basic block, if I understand it correctly. That would indeed make control flow sensitive analysis easy. Their sea of nodes representation does not have this property, so it is not immediately apparent under what control conditions a node may be executed. Their scheduler will place nodes in basic blocks at the end of the pipeline. I loved your paper about PBQP register allocation, by the way!
- Klathmon 10y agoThis is a fantastic write-up! While I've often felt many of the pain points in the article and they were never explained anywhere (that I saw anyway). I'd often profile/benchmark something, make sure it's fast enough to use in our performance critical section of the code, only to find that once in the application I'd only get a fraction of the speed I was expecting. I would then hop over to using --trace-opt only to find that functions were getting deoptimized or never optimized in the first place and I'd start playing the game of trying things here and there to get it to cooperate. And in some cases --trace-opt wouldn't tell me anything that I could usefully understand yet my code would still be slow. Here's to hoping that turbofan clears up a lot of these weird cases! And slightly off topic, but what are the plans for the dart VM? Is it going to end up using TurboFan or will it stay with Crankshaft?
- mraleph 10y ago> And slightly off topic, but what are the plans for the dart VM? Is it going to end up using TurboFan or will it stay with Crankshaft? Dart VM is a code base independent of V8, so V8's plans to adopt one or another compiler have no implications on Dart VM. Dart VM's IR is closer to Crankshaft, but it supports full language unlike Crankshaft (so in this sense it is closer to TurboFan). We currently have no plans to radically rework the compilation pipeline, because we see no need for that.
- bitmapbrother 10y agoThe Dart VM is also an integral component of Google's Fuchsia OS.
- mwcampbell 10y agoI think there's a lesson for application developers buried in here: If you have the freedom to choose the language and language features of your application, choose your language and language features so as to minimize the risk of performance cliffs such as those that the article discusses at the beginning. This probably means static typing, and static dispatch (i.e. not virtual functions) by default. And of course, a language like that can be compiled to JavaScript, e.g. Kotlin, C# via Bridge.net, or F# via Fable. By the way, I know this is a tenuous association, but to me, the name TurboFan makes me think of CPU-hungry code that cranks up the fan(s) on a user's laptop.
- wisebit 10y ago>Looking at it naively, it seems to follow the rules for the arguments object in Crankshaft I've never managed to find a good source on the V8 internals and how to target these optimizations (the "rules for the arguments object" the author alludes to). Any recommendations?
- cwmma 10y agothis [1] is probably what you want 1. https://github.com/petkaantonov/bluebird/wiki/Optimization-killers#3-managing-arguments https://github.com/petkaantonov/bluebird/wiki/Optimization-k...
- wisebit 10y agoThanks! The linked repo [1] is also great: [1] https://github.com/vhf/v8-bailout-reasons https://github.com/vhf/v8-bailout-reasons
- vhf 10y agoThey are complementary resources, "Optimization killers" helps you avoid pitfalls in practice, "v8-bailout-reasons" tries to document and explain the various Crankshaft bailouts.