This article is more than 1 year old

Facebook devs devise Hermes to push cross-platform JavaScript to godlike speeds

Not named after the French couturier but the Greek god of trade, roads, and thieves

Facebook on Thursday released a JavaScript engine called Hermes under an open source MIT license to improve the performance of React Native apps.

The ad biz made the announcement at the Chain React 2019 conference, which focuses on React Native development. React Native is an open source mobile application framework created by Facebook to develop apps for Android, iOS and Universal Windows Platform (UWP) using JavaScript, React (a JavaScript interface library) and native platform components. It's supposed advantage is that developers can target all three mobile platforms with a single code base; but as with any cross-platform framework, there are trade offs in terms of performance, security and flexibility.

Hermes aims to address the performance trade-off, which is particularly acute for Facebook because it has complicated JavaScript-dependent mobile apps. The amped-up engine is designed to reduce time to interaction (TTI), the time between app launch and app usability, a particularly important metric for mass market app makers), app size and memory usage.

As Google engineering manager Addy Osmani has observed, Google's V8 JavaScript engine spends a lot of time parsing and compiling JavaScript code before running it, leading to slow mobile application startup times. The parse and compile phases that precede execution of architecture-specific machine instructions can be 2-5x longer on mobile devices as they are on desktop devices, according to Osmani.

Hermes is intended as an alternative to Google's (Chromium's) V8, Apple's JavaScriptCore, Mozilla's SpiderMonkey and ChakraCore, the open source version of Microsoft's Chakra, which was left behind for V8 in Redmond's Chromium-based resurrection of its Edge browser.

But for now it's only an alternative in the context of React Native apps. Hermes hasn't been fitted for other projects that rely on a JavaScript engines, such as Node.js or frameworks like Electron (cross-platform apps using JavaScript alongside web tech rather than native code) that embed Chromium.


JavaScript tracking punks given a thrashing by good old-fashioned server log analytics


According to Facebook, there's no plan to push Hermes' beyond React Native to Node.js or to turn it into the foundation of a Facebook-branded browser. That's because it's optimized for mobile apps and wouldn't offer advantages over other engines in other usage scenarios.

Hermes tries to be efficient through bytecode precompilation – rather than loading JavaScript and then parsing it, Hermes employs ahead-of-time (AOT) compilation during the mobile app build process to allow for more extensive bytecode optimization. Along similar lines, the Fuchsia Dart compiler for iOS is an AOT compiler.

There are other ways to squeeze more performance out of JavaScript. The V8 engine, for example, offers a capability called custom snapshots. However, this is a bit more technically demanding than using Hermes.

Hermes also jettisons the just in time (JIT) compiler used by other JavaScript engines to compile frequently interpreted code into machine code. In the context of React Native, the JIT doesn't do that much to ease mobile app workloads.

The reason Hermes exists, as Facebook tells it, is to make React Native better. "Hermes allows for more optimization on mobile since developers control the build stack," said a Facebook spokesperson in an email to The Register. "For example, we implemented bytecode precompilation to improve performance and developed more efficient garbage collection to reduce memory usage."

Facebook, a company spokesperson said, is planning to publish benchmark figures to support its performance claims next week. In a discussion on Hacker News, Microsoft developer Andrew Coates claims that internal testing of Hermes and React Native in conjunction with Microsoft Office for Android shows TTI using Hermes at 1.1s, compared to 1.4s for V8, and with 21.5MB runtime memory impact, compared to 30MB with V8.

Hermes is mostly compatible with ES6 JavaScript but not completely. To keep the engine small, support for some language features is missing, like with statements and local mode eval().

A developer who works for a Facebook rival told The Register that the success of Hermes will remain tied to the success of React Native unless it gets taught how to compile to platforms other than Android. And for the foreseeable future, browsers can be expected to continue to use runtimes based on C++ for reasons of performance and portability. ®

More about


Send us news

Other stories you might like