WhoBuilt

JIT JS engine pipeline vs Hermes pipeline

Jun 30, 2021· 11 min· 1.7K views·Watch on YouTube

An unnamed Callstack speaker explains how Hermes shifts JavaScript compilation to build time, and why that suits React Native apps.

How JIT engines compile and run JavaScript

The speaker describes a typical JIT pipeline: parse JavaScript into bytecode, interpret it, then compile frequently used functions into machine code. Hot functions may receive further speculative optimization, with deoptimization if an assumption fails. These stages cost CPU and memory, and can leave multiple code versions in memory.

Hermes moves work to build time

Hermes compiles source on the developer’s machine, optimizes an SSA intermediate representation, and produces a bytecode bundle for the device. At runtime, the executable is memory-mapped and run without a JIT. The speaker says this is a deliberate choice for the React Native workflow.

Startup time shaped the choice

The speaker connects Hermes to React Native’s need for better time to interactive, especially on low-end devices. Facebook’s Marketplace tab was an example where slow initial loading and interactivity were a concern. Since React Native code is generally bundled with the app, its runtime environment is more controlled and its bytecode can be prepared ahead of time.

Different workloads favor different engines

Browser JavaScript varies widely, so browser engines use multiple JIT tiers to handle diverse workloads. Node.js often runs repetitive work for longer periods on powerful machines, which can justify paying a warm-up cost for optimized code. React Native workloads are typically more ephemeral: most startup functions run zero or one time, and later activity mainly responds periodically to user interactions.

Memory matters on mobile

The speaker adds that mobile memory constraints can make JIT compilation less attractive. They say React Native apps using JavaScriptCore typically do not use its JIT, while noting they do not have the full context for that behavior.

Takeaways

  • Choose compilation strategies around the app’s workload and startup needs, not only peak execution speed.
  • Precompiling bundled code can reduce work on the device when the runtime environment is controlled.
  • Measure how often functions run before investing in JIT optimization; many React Native startup functions may run only once or not at all.
  • Account for mobile memory use as well as CPU cost when deciding whether runtime compilation is worthwhile.

Mentioned in this talk

Search inside this talk

What was claimed 12

Related talks