Skip to content

Feature: Modernize @tensorflow/tfjs-react-native to support React Native New Architecture #8640

@sanjaiyan-dev

Description

@sanjaiyan-dev

System information

  • TensorFlow.js version (you are using): Latest (4.x)
  • Are you willing to contribute it (Yes/No): Yes

Describe the feature and the current behavior/state.
Currently, the @tensorflow/tfjs-react-native package relies on the legacy React Native architecture and several outdated or deprecated third-party dependencies. For example, it uses react-native-fs and @react-native-async-storage/async-storage, which do not fully leverage modern React Native capabilities. Additionally, it relies on the legacy expo-camera package. This current state blocks developers from adopting React Native's New Architecture (including bridgeless mode) and leaves significant performance optimizations on the table.

I am requesting a modernization of the React Native integration to support the New Architecture. The proposed feature enhancements include:

  1. Storage Migration: Replacing @react-native-async-storage/async-storage with react-native-mmkv. MMKV utilizes Turbo Modules and is approximately 25x faster than async-storage, which will drastically speed up model loading/saving operations.
  2. File System Update: Migrating from react-native-fs to @dr.pogodin/react-native-fs to ensure compatibility with the new architecture and improve tree-shaking capabilities.
  3. Expo Packages Upgrade: Updating Expo dependencies to their latest versions, notably migrating from the deprecated expo-camera to the modern expo-camera-next API.
  4. Component Modernization: Refactoring existing class components to functional components to take advantage of the React Compiler, reducing the need for manual memoization and improving overall UI performance.

Will this change the current api? How?
Yes, this will likely require a major version bump and introduce breaking changes.

  • Users will need to update their peer dependencies to align with modern standards (e.g., React 18+, React Native >= 0.77, and newer Expo versions).
  • The underlying storage mechanism will change to MMKV, which might affect developers if they are manually interfacing with the TFJS storage layer.
  • The camera component wrapper will transition to expo-camera-next, which has a slightly different underlying API compared to the legacy version.
    To ensure a smooth transition, we could release this behind a @beta tag first to allow the community to test the upgrade path before a stable release.

Who will benefit with this feature?
The entire React Native developer community using TensorFlow.js.

  • Developers will experience massive performance gains, especially in I/O operations and model caching.
  • Teams can safely upgrade their applications to React Native's New Architecture without TFJS acting as a blocking dependency.
  • Future-proofing the library ensures long-term support and alignment with the modern React Native and Expo ecosystems.

Any Other info.
I have already been working on this migration and have an open PR demonstrating these architectural changes here: #8521.

Because the scope of modernizing the architecture is quite large, I am fully willing to break down the implementation into smaller, more reviewable modular PRs (e.g., doing the Storage Migration first, then Dependency Alignment, File System, etc.) to make the review process as easy as possible for the maintainers.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions