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 ! |
|
Thanks for making these changes. The problem identified is legitimate, but I wonder if this coming from a few specific view managers? With static view configs, view manager constants shouldn't even really be needed anymore (unless our internal config differs here?) Adding a cache layer here which gets initialized eagerly is 1) risk of inconsistencies (what if the view manager config is actually dynamic based on some context?) and 2) may slow down the app in general since we're doing this so early on the startup path. |
Thank you for taking a look :) |
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.