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 |