Rousavy introduces VisionCamera and demonstrates a camera app with frame processors. These functions run on camera frames, and native plugins can perform tasks such as image labeling, object detection, and QR code scanning. His example uses ML Kit to label frames and return the results to JavaScript.
How JSI powers the most advanced Camera library (VisionCamera Frame Processing)
Speaker
Mark Rousavy of Callstack explains how VisionCamera frame processors use JSI for synchronous, high performance camera processing at React Native EU 2021.
Rousavy describes the React Native bridge as a batched communication layer that serializes messages, which adds delay and overhead. JSI provides a C++ interface to JavaScript runtimes, letting native code create values and functions that JavaScript can call synchronously. He demonstrates a native `add` function and explains that JSI values can be installed in the runtime’s global namespace.
Using React Native MMKV as an example, Rousavy shows how a module can install JSI functions before the JavaScript bundle runs, using the JavaScript thread and a runtime pointer passed into C++. He then explains VisionCamera’s frame object: a C++ host object exposes properties such as width and height by retrieving them from the native camera frame when JavaScript accesses them. This avoids copying or serializing the full image into JavaScript.
Rousavy explains that sending a camera frame through the bridge would require a large JSON message for every frame, and calling a native plugin would send data back across the bridge again. VisionCamera instead passes a host object to a frame processor running in a secondary JavaScript runtime created with Worklets. Plugins can be written in Swift or Objective-C on iOS and Java or Kotlin on Android, with JSI values converted to platform types.
Takeaways
- Use frame processors to run camera work on incoming frames, and limit their rate with `frameProcessorFps` when appropriate.
- Use JSI host functions when JavaScript needs direct synchronous access to native functionality.
- Represent large native data with host objects or typed arrays instead of expanding it into many individual JavaScript values.
- Install JSI modules on the JavaScript thread at the right point in runtime startup.
- Move expensive frame processing to a worklet runtime to keep React Native UI work responsive.
Mentioned in this talk
Search inside this talk
What was claimed 8
- usesVisionCamera uses JSI
“React Native VisionCamera”
1:40inWhen will the re-architecture (TurboModules, Fabric) rollout be available to the community?YouTube Verified4 sources· Talk
- usesReact Native MMKV uses JSI
“React Native MMKV”
1:40inWhen will the re-architecture (TurboModules, Fabric) rollout be available to the community?YouTube Verified4 sources· Talk
- featureVisionCamera: Provides frame processors that are called for camera frames and can invoke native functions synchronously.
“VisionCamera provides an API for this. It's called frame processors.”
YouTube Unverified1 source· Talk
- featureML Kit: Provides an API for labeling images.
“ML Kit has an API where we can label images.”
YouTube Unverified1 source· Talk
- featureJSI: Provides direct, synchronous access to the JavaScript runtime from native C++ code.
“It's completely synchronous, so the result returned by the host function can be used directly in JavaScript.”
YouTube Unverified1 source· Talk
- metricReact Native MMKV: About 30 times faster than AsyncStorage.
“It's about 30 times faster than AsyncStorage”
YouTube Unverified1 source· Talk
- featureReanimated: Its Worklet API can spawn a secondary JavaScript runtime for frame processing.
“spawn a secondary JavaScript runtime and run all of this code in parallel”
YouTube Unverified1 source· Talk
- integrates withVisionCamera integrates with Reanimated
“With JSI, we can use the Worklet API to spawn a secondary JavaScript runtime”
YouTube Unverified1 source· Talk






