Skip to content

Add loadReactNative(context, startReactHost) to start the ReactHost from Application.onCreate - #60061

Draft
tomekzaw wants to merge 1 commit into
react:mainfrom
tomekzaw:startup/eager-start
Draft

tomekzaw wants to merge 1 commit into
react:mainfrom
tomekzaw:startup/eager-start

Conversation

@tomekzaw

Copy link
Copy Markdown
Contributor

Summary:

On a cold start, the React instance (JS runtime, TurboModules, Fabric, bundle evaluation) is only created once the first Activity starts its surface, so all of it waits for Activity.onCreate. ReactHost.start() already exists to create the instance earlier, but the generated loadReactNative(this) entry point that apps call from Application.onCreate cannot use it.

This adds a loadReactNative(Context, boolean startReactHost) overload to the generated ReactNativeApplicationEntryPoint. With true it calls ReactHost.start() right after loading React Native, so instance creation and bundle evaluation overlap with the Activity being created. loadReactNative(Context) is unchanged. RNTester opts in.

Benchmarks (RNTester release, real phones, dex state verify, cold starts interleaved in blocks between the two builds, 18 launches per arm; TTFD = reportFullyDrawn() on RNTester's first React content, TTID = am start -W; medians, bootstrap 95% CI of the median difference):

Phone Cold TTFD before → after Δ TTFD Δ TTID
Galaxy A16 (Helio G99, Android 16) 336 → 317 ms −20 ms, −5.8% [−40, −3] +18 ms [+8, +53]
Galaxy A57 5G (Android 17) 202 → 190 ms −13 ms, −6.4% [−23, −5] +2 ms [−7, +10]
moto g57 power (Android 16) 261 → 251 ms −10 ms, −3.8% [−16, −2] 0 ms [−14, +9]
Pixel 9a (Android 16) 150 → 141 ms −10 ms, −6.3% [−15, −5] +2 ms [−2, +12]
OPPO CPH2269 (Helio G35, Android 11, OEM speed-profile) 1075 → 1056 ms −19 ms, −1.8% [−61, +40]; an earlier identical run: 1081 → 1017, −64 ms, −5.9% [−114, −22] +24 ms [−10, +54]

Warm starts (process alive) are unchanged: A16 −3 ms [−14, +6], moto g57 −4 [−24, +18], Pixel 9a 0 [−4, +6].

Trade-offs:

  • The first, empty frame can come later on mid-range phones (A16: +18 ms), because the JS and ReactHost threads now compete with the main thread during Activity creation. Content comes earlier on every phone measured.
  • The React instance is created for every process start, including ones that never show an Activity (headless tasks, push-triggered services). Apps where that matters should keep loadReactNative(this).
  • Bridgeless only: ReactApplication.getReactHost() must return the host.

Changelog:

[ANDROID] [ADDED] - loadReactNative(context, startReactHost = true) starts the ReactHost from Application.onCreate so bridgeless startup overlaps with Activity creation

Test Plan:

  • cd packages/gradle-plugin && ./gradlew :react-native-gradle-plugin:test --tests "*GenerateEntryPointTaskTest*" passes (template and expected output updated).
  • RNTester release (assembleRelease, arm64) built with the generated entry point containing the overload; launched on the five phones above, Components list renders, back + relaunch (warm) works.
  • Benchmarks above; each arm was installed with adb install -r + cmd package compile -m verify -f, launched with am force-stop + am start -W, values read from logcat Displayed / Fully drawn.

🤖 Generated with Claude Code

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 16, 2026
@facebook-github-tools facebook-github-tools Bot added p: Software Mansion Partner: Software Mansion Partner labels Nov 16, 2026
@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at e23eef9db7fc.

ios: no capture

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

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Software Mansion Partner: Software Mansion Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant