WhoBuilt

React Native CodeGen

Oct 9, 2019· 21 min· 2.1K views·Watch on YouTube

Speaker

At React Native EU 2019, Alexey Kureev of Facebook discusses React Native CodeGen and architecture with the Callstack conference audience.

Why the bridge can leave blank rows

React Native’s current architecture sends serialized messages between JavaScript and native code through an asynchronous bridge. When a fast scroll on a low-end device needs many new list rows, that back-and-forth can lag and leave blank space on screen.

JSI connects JavaScript and native code

Kureev points to browser APIs as examples of JavaScript calling native functionality through runtime extensions. React Native needs a shared interface for different platforms and JavaScript engines; he describes JSI, the JavaScript Interface, as that abstraction, with bindings that connect calls to native implementations.

CodeGen creates typed native contracts

Because JSI bindings are written in C++, Kureev proposes generating them from typed JavaScript definitions in Flow or TypeScript. CodeGen can also produce native artifacts such as Objective-C protocols and Java classes, giving implementations compile-time checks against the JavaScript API.

Compatibility and startup improvements

Generated types could help expose API differences across platforms and check whether over-the-air JavaScript updates remain backward compatible. CodeGen can produce a JSON schema for compatibility checks. Kureev also expects startup to improve because the app would no longer need to load every native module and build its JavaScript interface at launch.

Takeaways

  • Use typed API definitions to catch mismatches between JavaScript and native implementations at build time.
  • Treat cross-platform API parity as a design constraint; different parameter types can otherwise fail only at runtime.
  • Generate schemas and check them before shipping over-the-air updates that change native API usage.
  • Measure startup work that enumerates native modules; generating interfaces ahead of time may remove some launch-time overhead.

Mentioned in this talk

Search inside this talk

What was claimed 8

Related talks