Hermes In React Native

Hermes is an open source JavaScript engine designed by “Facebook“ specially to optimize the performance of React Native apps. It improves both the startup time and overall performance of the application, especially on Android device.

Why uses Hermes? :-

React Native uses JavaScript to run apps, and typically, it relies on engine like V8 (used in Chrome) or Java Script Core (used in safari). However these engines aren’t optimized for mobile performance, which can lead to slower app load times or higher memory usage, especially on lower-end device.

Hermes was introduced to address these issues by:

  1. Faster App Startup : Hermes compiles Java Script code into a highly optimized bytecode format before running the app, which reduce the time it takes to lead and start the app.

  2. Lower Memory Usage : It is designed to be lightweight, which makes it consume less memory, helping apps run more efficiently on devices with less RAM.

  3. Smaller APK Size : Hermes produces smaller APK ( Android Package Kit )sizes because its bytecode format is more compact.

Key Feature Of Hermes :-

  1. Ahead-of-time Compilation ( AOI ) : Unlike other java script engine that interpret java script code at runtime , Hermes compiles java script ahead of time into bytecode. This means the engine doesn’t have to parse and compile java script code when the app launches, resulting in faster startup times.

  2. Optimized For Mobile : Hermes is designed with mobile devices in mind, which are often more resource-constrained (in terms of CPU , memory) compared to desktops.

  3. Smaller Bundle Size : By compiling java script to bytecode, Hermes reduces the size of the java script bundle , which helps decrease the app size and improves the download / install time.

How To Enables Hermes In React Native :-

To use Hermes in your React Native project , especially on Android, you can follow these steps:

  • Install React Native CLI ( Command Line Interface ) and set up your project.

  • Enable Hermes by modifying your android/app/build.gradle file. find the project .ext.react section and enable Hermes by setting it to “true“ :

Project.ext.react = [
      enableHermes : true
]
  • Rebuild the app, since Hermes works with bytecode, you need to clean your project and rebuild it Run:
cd android && ./gradlew clean
npx react-native run-android

Example of performance improvement with Hermes:

Before Hermes :

  • App Startup time : 3 seconds

  • Memory usage : 150 MB

With Hermes enabled :

  • App Startup time: 1.5 seconds

  • memory usage: 100MB

This shows how Hermes can cut startup time in half and reduce memory consumption, especially on low-end devices.

Hermes is an open-source JavaScript engine by Facebook, designed to enhance the performance of React Native apps, particularly on Android devices. It reduces app startup times, lowers memory usage, and decreases APK sizes. Key features include ahead-of-time compilation for faster app launches and optimization for mobile resource constraints. Enabling Hermes involves modifying the build configuration of a React Native project, leading to noticeable improvements in app performance.

1
Subscribe to my newsletter

Read articles from akanksha srivastava directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

akanksha srivastava
akanksha srivastava