Facebook JavaScript engine boosts React Native on Android

Open-source Hermes JavaScript engine could be used to improve performance of all JavaScript-based mobile applications

Facebook has built a JavaScript engine, called Hermes, that improves the performance of React Native applications on Android devices. While the open-source engine is optimized for React Native today, it could be used to improve the performance of JavaScript-based mobile applications generally. 

Specifically, Hermes is geared to fast startup, leveraging compact bytecode and ahead-of-time static optimization. In many cases, enabling Hermes will improve startup time, decrease memory usage, and result in smaller app size.

Hermes currently is an opt-in feature in React Native. Most of Facebook’s React Native products on Android are already using Hermes, including Crisis Response and the Oculus companion app.

Hermes JavaScript engine features

Hermes capabilities include:

  • Instead of parsing and compiling JavaScript on-device while the user waits, that work can be done at build time.
  • Ahead-of-time compilation allows for more-complex optimizations. Identical functions can be found in a program and de-duplicated. Strings from JavaScript code can be packaged together into an efficient storage form with no runtime overhead.
  • A small Android APK size.
  • Bytecode can be memory-mapped and loaded from flash memory incrementally as needed.
  • Virtual address space is allocated in chunks on demand as needed, avoiding the need to estimate the heap size and minimizing overhead. Freed memory can be returned to the OS. Also, garbage collection pauses are minimized.
  • Implements JavaScript standards, with Hermes targeting ECMAScript 2015, also known as ES6. JavaScript features not commonly used in React Native applications have been omitted.

Facebook has also open-sourced Hermes’ integration with React Native, so developers can opt into using Hermes immediately. The company plans to build time and memory profiling tools for Hermes and to add support for the Visual Studio Code debugging protocol. 

Where to download Hermes

You can download Hermes from GitHub. Instructions for enabling the use of Hermes can be found on the React Native website.