Skip to content

[Android] Report JS thread work to Android performance hints - #60525

Open
hryhoriiK97 wants to merge 1 commit into
react:mainfrom
hryhoriiK97:js-thread-performance-hint
Open

hryhoriiK97 wants to merge 1 commit into
react:mainfrom
hryhoriiK97:js-thread-performance-hint

Conversation

@hryhoriiK97

Copy link
Copy Markdown
Contributor

Summary:

The JS thread works in short bursts, such as one React update, with idle time in between. The Android scheduler sees a mostly idle thread and keeps it on the slow cores, at low frequency. On a Pixel 9a, the same 341-view update takes 22 ms of JS this way and 7 ms when the thread is boosted. Android already gives the UI thread and RenderThread a performance hint session (ADPF) through HWUI; the JS thread has none.

Behind a new flag, enableJSThreadPerformanceHintAndroid (off by default), the bridgeless JS thread gets its own hint session on Android 12+:

A burst is reported when the next one starts, not when it ends. The system drops a session's boost when no reports arrive for a while. Reported at its end, a burst gave no speedup at all: the boost had expired by the time the next update started. Reported when work resumes, it applies to the work that is starting. Java has no public way to say "work is starting": Session.sendHint is hidden, and APerformanceHint_notifyWorkloadIncrease is NDK-only on Android 16+.

Some details:

  • Work that keeps the queue busy for longer than the target is also reported while it runs.
  • A report is capped at 1 s.
  • Durations are wall time.
  • Errors from the hint service turn the hint off; they are not thrown.

Cost: a faster core uses more energy. On the Pixel 9a, during the busy test below (an update every 200 ms), batterystats estimates the app's CPU power at +40% (0.177 → 0.249 mAh per minute). When the JS thread is idle, nothing changes. That trade-off is why the flag is off by default.

Changelog:

[ANDROID] [ADDED] - Add the enableJSThreadPerformanceHintAndroid feature flag, which reports JS thread work to Android performance hints so that long JS work runs on faster cores

Test Plan:

Unit tests: MessageQueueThreadBurstTrackerTest (6 tests) covers:

  • reporting when the next burst starts;
  • one report per burst;
  • back-to-back messages forming one burst;
  • empty bursts;
  • long busy work;
  • the cap.
./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest

1,125 tests in 146 suites pass. yarn android-api-build leaves ReactAndroid.api unchanged, node packages/react-native/scripts/featureflags/index.js --verify-unchanged passes, and yarn format-check-kotlin passes for the changed files.

Devices: RNTester release builds of this branch, with the flag off and on, three interleaved launches each.

  • Two Playground screens are measured:
    • a tree of 341 Views (not memoized) where one leaf changes size;
    • a list of 32 rows where one row's title text changes.
  • An update runs every 700 ms (tree) or 200 ms (list).
  • "JS" is the time from setState to the layout effect. "Mounted" is the time until UIManagerListener.didMountItems. Both are medians.
Device Screen JS, off → on Mounted, off → on
Pixel 9a (Android 17) tree 22.5 → 7.3 ms 32.8 → 16.1 ms
Pixel 9a list 19.5 → 5.5 ms 32.5 → 15.7 ms
moto g57 power (Snapdragon, Android 17) tree 13.3 → 9.1 ms 32.4 → 31.9 ms
moto g57 power list 41.6 → 10.1 ms 68.6 → 35.3 ms
Galaxy S10+ (Android 12, no hint support) tree no change no change
  • On the Pixel, both screens now mount one frame earlier.
  • On the moto, the tree screen still mounts at about 32 ms whatever the JS time. After an idle period this phone runs the app's frames at 30 Hz, so the mount waits for the next 30 Hz frame.

🤖 Generated with Claude Code

The JS thread works in short bursts separated by idle time, so the Android
scheduler keeps it on slow cores at low frequency. Behind the new
enableJSThreadPerformanceHintAndroid flag, the bridgeless JS thread now gets
an ADPF hint session (Android 12+). Each burst of messages is reported when
the next burst starts, because the session's boost expires during the idle
time before then.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Gregory Moskaliuk <gregory.moskaliuk@swmansion.com>
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026
@hryhoriiK97
hryhoriiK97 marked this pull request as draft December 4, 2026 07:41
@hryhoriiK97
hryhoriiK97 marked this pull request as ready for review December 4, 2026 09:43

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

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant