Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "CrankShaftScript" in Node.js?

Tags:

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:

https://github.com/nodejs/CTC/issues/146#issue-237435588

like image 665
Matt Hargett Avatar asked Jun 26 '17 16:06

Matt Hargett


People also ask

What is Deno node js?

Deno is a JavaScript and TypeScript runtime similar to Node. js, built on Rust and the V8 JavaScript engine. It was created by Ryan Dahl, the original inventor of Node. js, to counter mistakes he made when he originally designed and released Node.

Why Node js is used?

Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature. It's used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind.

What is Node js explain in detail?

Node. js (Node) is an open source development platform for executing JavaScript code server-side. Node is useful for developing applications that require a persistent connection from the browser to the server and is often used for real-time applications such as chat, news feeds and web push notifications.


2 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.

like image 129
Adam Avatar answered Oct 24 '22 07:10

Adam


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.

like image 30
Matt Hargett Avatar answered Oct 24 '22 08:10

Matt Hargett