Grepedia
NM

Nitro Modules

A high-performance React Native framework for building type-safe native modules using statically compiled JSI bindings and C++, Swift, or Kotlin.

Score0
About

Nitro is a high-performance framework designed for building native modules in React Native apps. Created by the team at Margelo, it enables developers to implement JavaScript objects directly in C++, Swift, or Kotlin, providing a faster and more type-safe alternative to standard module bridging techniques. Nitro leverages JSI (JavaScript Interface) and specifically utilizes jsi::NativeState to ensure efficient memory management and performance, allowing native objects to have proper prototypes and known memory sizes for garbage collection. By utilizing modern language features, Nitro bridges directly to Swift using the zero-overhead Swift-to-C++ interop, and to Kotlin via fbjni, eliminating the need for Objective-C or Java bridging layers.

The framework is built around the concept of Hybrid Objects, which are native objects that can be instantiated, passed around, and destroyed from the JavaScript environment. Nitro includes an optional code-generation tool called Nitrogen, which statically generates type-safe bindings from TypeScript interfaces. This ensures that the native implementation strictly adheres to the defined types, providing compile-time safety and eliminating common issues like null-pointer exceptions or unexpected type mismatches. Nitro supports asynchronous patterns through Promise.async and natively integrates with Swift concurrency and Kotlin coroutines, making it well-suited for high-performance or complex native functionality.

Some of the key features are:

  • High-Performance JSI Integration: Uses an optimized JSI foundation to provide superior throughput for native method calls compared to TurboModules or ExpoModules.
  • Static Type Safety: Employs the Nitrogen generator to produce type-safe C++, Swift, and Kotlin interfaces from TypeScript specs.
  • Direct Language Bridging: Bypasses traditional bridging languages by using Swift-to-C++ interop and fbjni for Kotlin to reduce runtime overhead.
  • Hybrid Objects: Implements native objects as first-class citizens that are accessible from JavaScript and automatically managed.
  • Modern Concurrency: Supports idiomatic async/await and coroutine patterns for non-blocking native operations.
  • Compile-Time Optimization: Utilizes C++ templates and constexpr features to minimize runtime overhead during type checking.

To use Nitro, developers integrate the library into their project and define Hybrid Object specifications using the .nitro.ts file format. The Nitrogen CLI then processes these files to generate the necessary boilerplate code, including autolinking configurations for iOS and Android platforms. Developers implement their logic in their chosen language—Swift, Kotlin, or C++—and the framework handles the registration and exposure of these objects to the JavaScript runtime via a centralized HybridObjectRegistry.

Some common use cases include:

  • Real-time Image Processing: Creating efficient native pipelines for capturing and manipulating camera frames using high-performance C++ or Swift code.
  • On-device Machine Learning: Executing high-speed TensorFlow Lite models or other local AI tasks where performance and low-latency interaction are critical.
  • High-Frequency Data Streams: Building modules that handle massive amounts of incoming data from sensors or hardware, requiring lightweight and efficient memory handling.
  • Custom Native SDK Integration: Exposing complex native SDKs to React Native with full type safety and modern language support.