AI summary by TwinMind
The New React Native Architecture
Theo - t3․gg
25m 58s
React Native New Architecture Overview
- React Native team rebuilt vast majority of core to address fundamental limitations
- New architecture encompasses multiple improvements: JSI, concurrent rendering, synchronous layouts
- Available as experimental opt-in since React Native 0.68, currently on 0.73
- Meta has proven this at scale in production apps since 2024
- Plans to make it default by end of 2024
Key Limitations of Legacy Architecture
- Prevented high-polish experiences due to fundamental design constraints
- Asynchronous bridge between JavaScript and Native caused performance issues
- Layout measurements caused visual jumps and intermediate states
- Limited ability to integrate native code efficiently
Synchronous Layouts and Effects
- Problem: On layout events applied after painting, causing visual jumps
- Solution: useLayoutEffect runs before render, preventing jank
- Example: Tooltip positioning now moves synchronously with target view
- Enables blocking render to prevent intermediate UI states
- Critical for responsive UI in VR, game consoles, desktop environments
Concurrent Rendering Features
- Supports React 18+ features: Suspense, transitions, automatic batching
- Automatic batching: Reduces re-renders, smoother UI with fewer intermediate updates
- Transitions: Mark updates as lower priority, allowing interruption for higher priority updates
- Performance comparison shows significantly smoother rendering for rapid state updates
- Enables better conformance between web and native React development
JavaScript Interface (JSI) - Native Binding Revolution
- Major change: Removes asynchronous bridge between JS and Native
- JS can hold direct reference to C++ objects and vice versa
- Eliminates serialization costs for native method invocation
- Enables shared memory between JS and C++ without async layer transitions
JSI Use Cases and Examples
- Vision Camera: Processes 10MB frame buffers (1GB/second) in real time
- Database integration: Direct access to native databases like SQLite
- Cross-platform consistency: Same C++ code for color math across all platforms
- Twitch example: C++ color transformation for consistent chat colors across platforms
- Removes serialization overhead from core component rendering (View, Text elements)
Performance Benchmarks
- Android (Pixel 4): 1500 views: 282ms → 258ms, 5000 views: modest improvement
- iOS (iPhone 12): Significantly larger performance gains
- Analysis: iOS shows bigger percentage improvement due to higher baseline performance
- Android performance limited by Java/platform architectural decisions
- JSI particularly beneficial for iOS users who expect higher performance standards
Flash List Performance Improvement
- New list component for long lists with extensive data
- Performance gains: Up to 5x improvement in UI thread, 10x+ in JS thread
- Tested on Android Moto G10 (worst-case scenario)
- Addresses common performance issues that affect both React Native and native Swift/Java implementations
Future Capabilities and Web Alignment
- New architecture required for React Server Components in React Native
- Enables use of Suspense, useTransition in mobile apps
- Web alignment: Active research area for code sharing between web and native
- React Strict mode exploration for cross-platform code reusability
- Yoga (flexbox implementation) improvements for layout consistency
- Event loop model changes, DOM traversal APIs for better web conformance
Adoption Recommendations
- Production apps: Wait for official release (end of 2024) for best experience
- Library maintainers: Recommended to enable and verify use cases work
- Community resources available through React Native New Architecture working group
- Migration documentation and discussion forums provided
Technical Architecture Components
- JSI: Direct C++/JS object references without serialization
- Concurrent renderer: React 18 features, automatic batching
- Synchronous layout effects: Prevents visual jumps
- Native module integration: Seamless C++ code integration
- Cross-platform consistency: Shared native code across iOS/Android/desktop/VR
