There are more and more references in the Node.js community to "CrankShaftScript" (and "CrankShaftJS") on Twitter, GitHub, and Facebook group discussions. I thought Node.js was written in C++ and JavaScript, so what is CrankShaftScript referring to in performance regression bugs like this one:
3 Answers
CrankShaftScript is the name given by the community to JS idioms (such as certain types of loops) that run faster(est?) on V8's CrankShaft engine.
CrankShaft is being replaced by an engine named TurboFan. Lots of JS code written by devs over the years has been written specifically to run fast on CrankShaft (e.g. written in "CrankShaftScript") using the known idioms that run fast on CrankShaft - this is no longer necessarily the case because the V8 engine is now different and the code that ran fastest on CrankShaft is not necessarily guaranteed to run fastest on TurboFan.
In case my answer is too verbose, here's a great comment on the NodeJS Benchmarks thread that may detail it better:
...I noticed that some parts of Node core are sort-of written in CrankshaftScript, i.e. carefully tuned towards stuff that works extremely well in Crankshaft.

- 51,445
- 11
- 72
- 100
CrankShaftScript is a community-adopted term used for non-idiomatic and/or non-standard compliant JavaScript that will only execute and/or perform well in the specific versions of the v8 JavaScript runtime that employ the CrankShaft JIT compiler. Specific examples include: loops written in a difficult-to-maintain fashion to work around JIT optimization deficiencies in v8, and use of v8-specific built-in functions/globals.
This term was originally coined to describe some root performance issues in node-chakracore and spidernode, which are Node.js distributions that employ the ChakraCore and SpiderMonkey runtimes instead of v8.
It is now being used as shorthand to explain why the Node.js 8.1 release series, which updated to a newer version of v8, has several performance regressions in micro- and macro-benchmarks due to v8's CrankShaft JIT being superseded by TurboFan (sometimes referred to as "TF"). As in these issues:
- https://github.com/nodejs/node/issues/11851#issuecomment-287253082
- https://github.com/nodejs/CTC/issues/146#issuecomment-310229393
- https://twitter.com/matteocollina/status/870580613266501632
For these reasons, the Node.js community is actively working on excising instances of CrankShaftScript in Node.js core code, as well as in common npm packages. This should help alternative Node.js distributions like node-chakracore perform better and ease the risk of future upgrades to the JavaScript runtime in Node.js.

- 1,906
- 1
- 17
- 37
-
1A version of node v8.x with V8 5.9+ (which enables TurboFan by default) has *not* been released yet as of this writing. Node v8.0.0 did however bring V8 5.8 (although that version of V8 does not enable TurboFan by default). – mscdex Jun 26 '17 at 17:33
-
thanks for the clarification! I've edited the question. – Matt Hargett Jun 26 '17 at 17:35
-
1My comment is still relevant for node v8.1.x, which only has V8 5.8. While there may have been some regressions with 5.8, it's not because of the switch to TurboFan as the default because as previously stated, the switch of the default engine only happened in 5.9. Also, node v8.1.x will never see a V8 bump to 5.9+ (only node v8.2.x or later) due to semver. – mscdex Jun 26 '17 at 18:04
-
Is there any documentation on what these idioms are? – Bergi Jun 26 '17 at 19:00
-
The key point is that it's *optimized* for Crankshaft, which mostly means avoiding some things (like `try..catch`) that Crankshaft doesn't like. "CrankshaftScript" code is absolutely standards compliant, and would run anywhere, it just happens to be optimized for Crankshaft. – jmrk Jun 28 '17 at 11:04