Hermes: An open source JavaScript engine optimized for mobile apps, starting with React Native

Mobile applications are growing larger and more complex. Larger apps using JavaScript frameworks often experience performance issues as developers add features and complexity. These issues are gene…

Marc Horowitz
8 min readintermediate
--
View Original

Overview

Hermes is an open-source JavaScript engine developed by Facebook, specifically optimized for mobile applications, particularly those using React Native. The engine aims to enhance performance metrics such as time to interact, download size, and memory utilization, addressing the challenges posed by mobile device constraints.

What You'll Learn

1

How to integrate Hermes into your React Native applications

2

Why bytecode precompilation enhances mobile app performance

3

When to use lazy compilation for faster development cycles

Prerequisites & Requirements

  • Familiarity with React Native and JavaScript
  • Access to build.gradle files for configuration

Key Questions Answered

How does Hermes improve performance for React Native apps?
Hermes enhances performance by focusing on key metrics such as time to interact, download size, and memory utilization. It achieves this through bytecode precompilation, which reduces startup time, and by avoiding Just-In-Time (JIT) compilation, which can negatively impact time to interact on mobile devices.
What architectural decisions were made in Hermes for mobile optimization?
Hermes was designed with mobile constraints in mind, implementing features like bytecode precompilation to reduce startup delays, a lack of JIT compilation to maintain low memory usage, and a garbage collector that minimizes memory footprint, all tailored for mobile environments.
What are the key features of Hermes' garbage collector?
Hermes' garbage collector features on-demand allocation, noncontiguous virtual address space, moving objects for defragmentation, and a generational approach to reduce scanning time. These features are crucial for efficient memory use on mobile devices with limited resources.
How can developers debug applications using Hermes?
Developers can debug applications running on Hermes using Chrome remote debugging via the DevTools protocol. This allows for native debugging of applications, improving the development experience by enabling direct interaction with the Hermes engine.

Key Statistics & Figures

Time to interact (TTI)
Significantly improved
Hermes optimizes TTI by reducing the startup delays associated with traditional JavaScript engines.
Application size reduction
Decreased overall application size for Android React Native apps
Hermes achieves this through smaller native code size compared to traditional JavaScript sources.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Javascript Engine
Hermes
Optimized for mobile applications, particularly React Native.
Framework
React Native
Used for building mobile applications that can leverage Hermes.

Key Actionable Insights

1
Integrate Hermes into your React Native projects to significantly improve app performance.
By using Hermes, developers can enhance the user experience on mobile devices, particularly in terms of startup time and memory efficiency, which are critical for maintaining smooth performance.
2
Utilize bytecode precompilation to optimize your app's loading times.
Precompiling bytecode allows for faster execution and reduced memory usage, which is particularly beneficial for applications targeting lower-end mobile devices.
3
Leverage the lazy compilation feature during development for rapid iteration.
This approach allows developers to quickly test changes without the overhead of full bytecode compilation, maintaining a fast development cycle while still preparing for production optimization.

Common Pitfalls

1
Neglecting to configure build.gradle files correctly can lead to integration issues.
Developers must ensure that the Hermes settings are properly defined in their build.gradle files to avoid runtime errors and to fully leverage Hermes' performance benefits.

Related Concepts

Javascript Performance Optimization
Mobile App Development
React Native Enhancements