WhoBuilt

Static Hermes: the Next Generation of Hermes

Sep 25, 2023· 26 min· 17K views·Watch on YouTube

Speaker

Tzvetan Mikov, who helped create the Hermes JavaScript engine at Meta, presents Static Hermes at React Native EU 2023, hosted by Callstack.

Why compile JavaScript to native

Mikov introduces Joe Native, whose React Native app has fast startup but stutters during demanding work such as scrolling long lists and complex animations. Profiling and rewriting JavaScript cannot overcome the interpreter’s performance limits, while C++ extensions can be difficult to write and maintain. Static Hermes aims to compile selected, typed JavaScript ahead of time, leaving the rest of the app on Hermes bytecode.

Sound types and runtime checks

JavaScript functions can receive values of many types, making efficient native compilation difficult. TypeScript and Flow annotations alone are unsound: Mikov’s example passes undefined from out-of-range array access into a function annotated to receive numbers. Static Hermes adds opt-in runtime checks that throw a range exception, ensuring values match declared types in compiled code; existing Hermes code can coexist with it.

Native compilation performance

Mikov demonstrates Static Hermes on the math-heavy nbody.js benchmark. Its initial native version ran in 550 milliseconds, matching Hermes, while a later version was 10 times faster; he said the team saw potential for 20 times the speed. He also shows compact ARM64 output and says other benchmarks achieved up to five times the speed, with further work underway.

Zero-cost native integration

Sound types also enable Static Hermes to call native platform functions with no conversions, allocations, or indirections. Mikov reports call overhead 15 to 80 times lower than JSI. He explains that native calls require explicitly marked unsafe sections, then demonstrates JavaScript bindings to SQLite and a call to C’s getenv function, without writing C++.

Project status and community feedback

Mikov says Static Hermes is a work in progress and not yet suitable for general use; it can be difficult to use and some parts are broken. TypeScript support was contributed by Amazon, while the Hermes team had added Flow support. He invites feedback through Discussions on the Hermes GitHub repository and points viewers to benchmark and FFI examples.

Takeaways

  • Use native compilation selectively for performance-critical JavaScript while leaving other code on Hermes bytecode.
  • Type annotations do not guarantee runtime values; sound typing requires checks for cases such as out-of-range array access.
  • In the demonstrated nbody.js benchmark, native compilation improved runtime by 10 times over Hermes.
  • Zero-cost FFI can reduce native-call overhead substantially, but calls require deliberate use of unsafe code.
  • Treat Static Hermes as experimental based on this presentation; Mikov described it as difficult to use and still incomplete.

Mentioned in this talk

Search inside this talk

What was claimed 9

Related talks