Android: stop re-arming the idle DISPATCH_UI Choreographer frame callback (behind feature flag) - #58378
Open
capt-muji wants to merge 1 commit into
Open
Conversation
DispatchUIFrameCallback.doFrameGuarded re-schedules itself unconditionally in its finally block, running at vsync rate while no mount items are pending. Behind disableIdleMountItemFrameCallbackRearmAndroid (default off): the finally re-schedules only while items remain pending, and MountItemDispatcher notifies its listener when items are queued (any thread) so FabricUIManager can re-arm the callback - covering off-UI-thread view commands that previously relied on the always-armed pump.
3 tasks
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D119071289. |
4 tasks
Author
On-device validation (OnePlus 3T, Android 9 / API 28, bridgeless Release)Backported onto Result: DISPATCH_UI posts once (the initial mount) and then 0 at idle — the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stop re-arming the idle
DISPATCH_UIChoreographer frame callback (Android)Part of #58367. Split from #58368 per review feedback (one PR per pump, each behind a feature flag).
Summary
FabricUIManager.DispatchUIFrameCallback.doFrameGuardedre-schedules itself unconditionally in itsfinallyblock, so theDISPATCH_UIChoreographer callback runs at vsync rate forever — including while no mount items, pre-mount items or view commands are pending.This PR makes the re-schedule demand-gated, behind
ReactNativeFeatureFlags.disableIdleMountItemFrameCallbackRearmAndroid(default false = current behavior;ossReleaseStage: 'experimental'):doFrameGuarded'sfinallyonly re-schedules whilemMountItemDispatcher.hasPendingItems()(new helper onMountItemDispatcher).dispatchCommandare@AnyThread; JNI mount-item scheduling also queues cross-thread) and previously relied on the always-armed callback for eventual dispatch.MountItemDispatchernow notifies its listener (onItemsQueued, called fromaddMountItem/addViewCommandMountItem/addPreAllocateMountItem, flag-gated) andFabricUIManagerre-arms by hopping to the UI queue —schedule()is idempotent (mIsScheduledguard) and stays UI-confined. Without this, off-UI-thread items could starve at idle; this is the re-arm-trigger completeness point called out in the review of fix(android): stop re-arming idle Choreographer frame callbacks at vsync rate #58368.Foregrounding / backgrounding
onHostResume→resume()(re-schedules) andonHostPause→pause()(mShouldSchedule = false;schedule()no-ops) are untouched. Items queued while paused are dispatched after resume, as onmain. Items arriving on the UI thread during a commit keep the existing inline dispatch path (scheduleMountItemrunstryDispatchMountItemsin a guarded runnable); items added during a dispatch leavehasPendingItems()true, so thefinallyre-arms.Rollout
Flag:
disableIdleMountItemFrameCallbackRearmAndroid—defaultValue: false,expectedReleaseValue: true,ossReleaseStage: 'experimental'. With the flag off, behavior is identical to currentmain(onItemsQueuedis never invoked; thefinallyre-schedules unconditionally).Test plan
defaultValue): both new paths are inert../gradlew :packages:react-native:ReactAndroid:compileReleaseKotlin :packages:react-native:ReactAndroid:compileReleaseJavaWithJavac.adb shell atraceshowsDISPATCH_UIdoFrames drop to ~0 with a static UI; any render (navigation, state updates) re-arms and commits land the same frame or the next;dispatchCommandfrom JS (e.g. scroll-to flows) still executes promptly at idle; background/foreground round-trips keep the UI responsive.Changelog:
[Android] [Fixed] - Stop re-arming the DISPATCH_UI Choreographer frame callback at vsync rate while no mount items are pending; queueing items re-arms it (behind
disableIdleMountItemFrameCallbackRearmAndroid)