January 19, 2016 9:23 am

Submitting a Pull Request to Node.js with ChakraCore

By / Principal PM Manager, Chakra

Node.js continues to be a very successful and powerful cross platform technology for building apps that can run on anything from small IoT devices to large scale services that run in the cloud. We believe allowing more Node.js developers to target more platforms is key to its future growth. To do our part in growing the Node.js pie, last year we introduced support for Node.js with Chakra to extend the reach of Node.js and allow developers to target a brand new platform called Windows 10 IoT Core. So far Node.js with Chakra has been actively updated and iterated upon at our own repository, with the intention to merge it with the mainline after stabilizing the code.

Today we hit that major milestone on our roadmap by submitting a pull request to Node.js mainline to enable Node.js to work with ChakraCore.

The recent open-sourcing of ChakraCore gives us the opportunity to develop in the open and align better with Node.js release schedules, in addition to expanding our support for Node.js across the broader Windows ecosystem – starting with Windows 7 SP1 and beyond. Here are some important things to know about this pull request.

Support for ChakraCore JS Engine

This pull request enables Node.js to optionally use the ChakraCore JavaScript engine. Chakra Shim, which is a layer on top of the ChakraCore JS Engine, enables building and running Node.js with ChakraCore. This shim implements the most essential V8 APIs so that the underlying JavaScript engine change is transparent to Node.js and other native addon modules written for V8. All that is needed is to rebuild Node.js executable and native addon modules with ChakraCore.

Diagram showing architecture of Node.js with ChakraCore using the Chakra Shim

Architecture: Extending Node.js with ChakraCore

ChakraCore is a fully capable JavaScript virtual machine that has the same key characteristics that are supported by Chakra. You can learn more about ChakraCore in our blog post announcing the project. ChakraCore is independent from Windows 10 and is supported on Windows 7 SP1 and up. We are working on taking ChakraCore cross-platform, starting with Linux, as described at the ChakraCore roadmap. ChakraCore also has capabilities to turn off JIT compiler and specify thresholds for resource consumption, both of which significantly reduce the resource requirements and make it attractive for resource constrained hardware scenarios.

State of module compatibility

npm modules are critical to any Node.js project. The vast majority of npm modules are JavaScript-based and should continue to work well with ChakraCore. There is a small subset of modules that are natively bound to V8 APIs and can run into compatibility issues with a different VM or even a different version of V8. This is the reason why Native Abstractions for Node.js (NAN) was born to allow for better module compatibility.

We embraced this abstraction and ensured all NAN based modules are fully supported in Node.js with ChakraCore. We also intend to actively participate in the native module abstraction efforts by contributing our learnings, architectural ideas, prototypes etc. in the community working group. While the abstraction effort is long-term approach, on a shorter term we would love to hear from the community on our issues page if there are any key compatibility gaps still remaining. This will allow us to prioritize the modules that need to be made compatible.

Evaluating Performance

JavaScript engine performance is key to any successful Node.js application or service. It impacts not only the user experience but also impacts cost for compute resources. Historically, the Chakra team has focused on real world performance over benchmark performance. To evaluate this, we tested TypeScript compile times, as it represents a large JavaScript program that can give us an indication of underlying JavaScript engine performance in the Node.js environment. The chart below shows various TypeScript workloads, compiled using the TypeScript compiler with Node.js and Node.js with ChakraCore. ChakraCore shows 10% -30% better throughput on these tests.

Chart showing Typescript compile times with Node.js. Node.js with ChakraCore is 10-30% higher throughput in these tests.

TypeScript compiler performance
(System info: Intel Core i5-34755 @ 2.90Ghz with 4.0GB RAM running Windows 10)

When compared to the baseline of default Node.js performance, Node.js with ChakraCore is more performant than Node.js with Chakra just a few months ago. The following graph plots slower-than-baseline tests below the blue line and the tests that were better than baseline above the blue line. While there’s still work to do, we’re happy that the curve is moving in the right direction.

Graph comparing Node.js benchmark performance (baseline) with Chakra and now with ChakraCore.

Node.js Benchmark performance
(System info: Intel Core i5-34755 @ 2.90Ghz with 4.0GB RAM running Windows 10)

Our performance testing did identify some differences in the hosting surface that can boost ChakraCore’s performance with Node.js. Continuing to invest in understanding and improving real world performance is a priority for the team. Going forward, we also want to work with the benchmarking workgroup and the community to identify real world performance scenarios for Node.js.

Looking ahead

The team is working on adding two key capabilities around diagnostics support. The first capability is focused on Modern Diagnostic APIs. While developers can use “console.log” style debugging when using Node.js with ChakraCore today, we are building a new set of Modern Diagnostic APIs, which break away from dependencies on COM and will help make the debugging experience of Node.js with ChakraCore interoperable with existing Node.js diagnostic tools. For the second, we are teaming up with Microsoft Research to advance the state of the art of Node.js debugging, with a feature we call Time Travel debugging.

Taking ChakraCore cross-platform is also high on our roadmap. Node.js is a truly cross-platform technology, and we believe that any JavaScript engine that powers it should be cross-platform as well. We are starting with Linux, and will keep the roadmap updated with details and status as we make progress. As a first step towards enabling cross-platform support, we have cleanly separated out Chakra’s JIT compiler producing a build configuration that builds just the interpreter and runtime. This smaller build target is what we will initially enable cross platform. We would love hear what the community thinks about which other platforms we should target. ChakraCore is open for taking contributions and if interested, we invite you to participate in porting ChakraCore to the platform of your choice.

You can participate or follow the work as it progresses on ChakraCore GitHub repository.

Try it out for yourself

You can try Node.js with ChakraCore with your existing scripts using this temporary installer, which installs Node.js with ChakraCore binaries without having to build it manually from the sources. We plan to work with the Node.js build working group to make these binaries available from an official Node.js channel. The current installer installs Node.js with ChakraCore side-by-side with an existing default Node.js installation without disturbing it, so that you can give it a try and share your feedback without disturbing your existing setup.

Our journey with Node.js has just started. We are committed to developing in the open, while working with the Node.js TSCs/CTC and the wider Node.js developer community. We truly see the power of Node.js, admire this community for what it has achieved so far, and we are excited to learn and contribute even more!

We welcome your feedback on our pull request to Node.js mainline. Try Node.js with ChakraCore and let us know your feedback. Finally, you can always reach us on Twitter at @ChakraCore or visit ChakraCore’s GitHub repository and leave us a note by opening an issue or via Gitter. We look forward to hearing from you!

Arunesh Chandra, Sr. Program Manager, Chakra

Gaurav Seth, Principal PM Manager, Chakra

Updated January 21, 2016 2:00 pm

Join the conversation