Skip to content

perf(android): create view managers on demand - #813

Open
imranbarbhuiya wants to merge 1 commit into
appandflow:mainfrom
imranbarbhuiya:refactor/android-on-demand-view-managers
Open

imranbarbhuiya wants to merge 1 commit into
appandflow:mainfrom
imranbarbhuiya:refactor/android-on-demand-view-managers

Conversation

@imranbarbhuiya

Copy link
Copy Markdown

Summary

On Android with the New Architecture (bridgeless), React Native builds the view config (props and events) of every view manager in an eager ReactPackage when JS first reads UIManager. That happens on the JS thread during startup, before the first screen renders. SafeAreaContextPackage now implements ViewManagerOnDemandReactPackage. React Native then lists RNCSafeAreaProvider and RNCSafeAreaView and builds each config only when JS first uses that view. MainReactPackage, react-native-gesture-handler and react-native-svg already work this way.

  • getViewManagerNames returns both names (REACT_CLASS).
  • createViewManager creates only the requested manager.
  • createViewManagers is unchanged, for setups that call it.

The gain needs React Native 0.89+, which includes react/react-native#58097. On older versions, UIManager.js builds every lazy config anyway, and the change is harmless. Two view managers are a small share on their own. Across all packages in a production app, building view configs on demand cut JS start → first mount from 110 ms to 66 ms (react/react-native#59173). The same change is open for react-native-screens (software-mansion/react-native-screens#5221) and react-native-keyboard-controller (kirillzyusko/react-native-keyboard-controller#1767).

Test Plan

Example app, debug build on a Pixel 9 emulator (Android 16), New Architecture (React Native 0.85):

  • SafeAreaView Example, SafeAreaView Edges Example and Hooks Example (from the dev menu) render with the expected insets: top 54, bottom 24, provider frame 411×923.
  • Logcat has no errors. ViewManagerPropertyUpdater: Could not find generated setter warnings for SafeAreaProviderManager also appear without this change.
yarn test
# Test Suites: 5 passed, 5 total
# Tests:       34 passed, 34 total

yarn format:spotless:check
# BUILD SUCCESSFUL

@vercel

vercel Bot commented Nov 15, 2026

Copy link
Copy Markdown

@imranbarbhuiya is attempting to deploy a commit to the appandflow Team on Vercel.

A member of the Team first needs to authorize it.

@floco-af floco-af left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review (Floco, App & Flow's coding agent). Static review only; I did not build or run this on a device.

Correctness

  • getViewManagerNames returns RNCSafeAreaProvider and RNCSafeAreaView. These are the REACT_CLASS constants that both managers return from getName(), so the names RN looks up match.
  • createViewManager returns a new manager for each name and null for anything else. That matches the @Nullable contract of ViewManagerOnDemandReactPackage.
  • createViewManagers is unchanged, so setups that call it directly (eager packages, old architecture) still work.
  • The interface signatures match RN 0.76 (Java) and 0.85 (Kotlin), so the change should compile across the supported range. The peer dependency is *.

Platforms and breaking changes

  • Android only. No JS, iOS or API change.
  • On RN versions without react/react-native#58097 the PR says it is a no-op, which fits the code.

Tests and validation

  • Nothing exercises this class (the JS test suite doesn't cover the Android package), so there is no regression test to add.
  • The perf numbers come from react/react-native#59173, not from this library, and I did not reproduce them.
  • The PR describes a manual run of the example app on a Pixel 9 emulator, and I couldn't confirm that.
  • The CI status shown is only the Vercel authorization check. No build ran.

Verdict: looks good. The change is small and contained. The only thing I'd want before merging is a Kotlin compile and a smoke run of the example app on Android, which maintainers can do quickly.

@imranbarbhuiya

Copy link
Copy Markdown
Author

Both ran: I built the example with this change (assembleDebug, new architecture), which compiles the Kotlin, and ran the SafeAreaView, Edges and Hooks examples on a Pixel 9 emulator (Android 16). The insets were correct and there were no errors. CI only shows the Vercel check because it's waiting for authorization.

@floco-af floco-af left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up from Floco (App & Flow's coding agent), after the author's note that the example was built and run on a Pixel 9 emulator.

What I ran on c4dd7ed: yarn validate:eslint, yarn validate:typescript and yarn validate:jest all pass (5 suites, 32 passed, 2 skipped). The change only touches SafeAreaContextPackage.kt, so none of these exercise it.

What I could not do: build the Android example or run it on a device. The remote Mac mini I use for Android builds refused the build in this run, and this host has no Android emulator. So I can't independently confirm the Kotlin compile or the emulator run the author describes. The only CI check on the PR is the Vercel authorization one, so no build has run there either.

Verdict unchanged: looks good. The change is small and contained. A maintainer should still do one Android build and smoke run of the example before merging.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants