r/reactnative • u/Desperate_Door1709 • 9h ago
Code Splitting - Lazy Evaluation in React Native
I have built a bare react native cli toy project to study how lazy evaluation works and how it effects app cold start and TTI.
This is the nested navigation architecture of the app. I added some expensive computations in inner screens just to test the lazy evaluation.
App
└── RootNavigator (native stack)
├── MainTabs (bottom tabs, lazy={true})
│ ├── HomeTab → HomeStack
│ │ ├── Home
│ │ └── HomeDetail
│ ├── ProfileTab → ProfileStack
│ │ ├── Profile
│ │ ├── ProfileSettings → chartData
│ │ └── AccountSecurity → securityCrypto
│ └── AnalyticsTab → AnalyticsStack
│ ├── AnalyticsDashboard → heavyMath (+ 50M local loop)
│ ├── Reports → reportEngine
│ └── DeepInsights → insightsEngine + chartData
└── AppSettings (modal)
referred the following guide to implement this:
https://reactnative.dev/docs/optimizing-javascript-loading
Problems:
-> while the TTI and cold start times increased drastically for initial screens, lazy evaluation of inner screens is being effected.
Eg: when we click on a button navigating to an inner screen that has a lazily evaluated js code, the button stays unresponsive for a few seconds before navigating. Also the TTI of the screens has also increased.
I tried preloading the screens which are immediate siblings but while their code is being evaluated the currently active screen stays unresponsive.
Technique used: Inline requires, Lazy Loading, Hermes engine
Expensive computations employed in screens:
I know these computations are an overkill but its just to test.
I would appreciate any suggestions, insights or any knowledge you could share on this.
| Module | Work | Scale |
|---|---|---|
AnalyticsScreen (inline) | Sum 0…n | 50M iterations |
heavyMath | Rolling checksum (checksum + i*31) % 1e9+7 | 40M |
reportEngine | Aggregate + sample rows | 35M |
securityCrypto | FNV-style hash over seed | 30M |
chartData | Area + sparse points | 28M |
insightsEngine | 1200×120 matrix + extra burn | 25M |
View all comments
Show parent comment
1
u/Im_ProBro 5h ago
+1