r/reactnative • • 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.

ModuleWorkScale
AnalyticsScreen (inline)Sum 0…n50M iterations
heavyMathRolling checksum (checksum + i*31) % 1e9+740M
reportEngineAggregate + sample rows35M
securityCryptoFNV-style hash over seed30M
chartDataArea + sparse points28M
insightsEngine1200×120 matrix + extra burn25M
2 Upvotes

2 comments sorted by