Cache UIManager constants in bridgeless new architecture on Android (Improve app start on low end/mid android by 150-300ms#56078
Conversation
|
Would it make sense to cache this in JS instead? We’d also want to have a feature flag for this. |
That sounds like a cleaner solution. I first use this optimisation with birdgeless off environment and then UIManager created constants in constructor. If in bridgeless the old paper UIManager is no longer created I think js would be cleaner. Let me test that and add a feature flag. |
|
@javache |
31cb45e to
74a915d
Compare
|
Hey @javache ! |
Summary:
Motivation: startup in bridgeless + new architecture was spending significant time in UIManager host functions (
getConstants/getConstantsForViewManager) even on repeated launches.This PR adds Android-side caching for UIManager constants and lazy view manager constants, preloads them early on app startup, and reuses them from
UIConstantsProviderBindingto avoid recomputing on subsequent runs.It also adds cache identity validation so stale cache is not reused after app/bundle changes (including OTA/file-bundle changes). Cache is only used when identity matches; otherwise it safely falls back to normal computation and refreshes cache.
Changelog:
[ANDROID] [CHANGED] - Cache and preload UIManager constants in bridgeless new architecture and invalidate cache when app/bundle identity changes.
Test Plan:
Build/install RNTester release on device:
./gradlew :packages:rn-tester:android:app:installReleaseBUILD SUCCESSFULandInstalled on 1 device.Capture Hermes sampling profiles on release (two sequential launches, 10s window via
react-native-release-profiler):yarn workspace @react-native/tester react-native-release-profiler --fromDownload --raw --appId com.facebook.react.uiapp/Users/szymonkapala/work/react-native/.tmp/rntester-profiler-verify-20260312-214548/run1.cpuprofile.txt/Users/szymonkapala/work/react-native/.tmp/rntester-profiler-verify-20260312-214548/run2.cpuprofile.txtProfile comparison (sample-based):
getConstantsForViewManagerpresent (41samples),getConstantspresent (1sample).getConstantsForViewManager0samples,getConstants0samples.This verifies first-run population + second-run reuse behavior with the new cache identity checks.