Repository navigation
Conversation
robhogan
force-pushed
the
robhogan/batch-set-native-props
branch
4 times, most recently
from
November 28, 2026 02:03
7156d8f to
5a7beb5
Compare
Every `setNativeProps` call commits the shadow tree. The commit clones the node's ancestors, and cloning a parent with a new child list also clones each of its other children (`YogaLayoutableShadowNode::adoptYogaChild`). While `enableAccumulatedUpdatesInRawPropsAndroid` is off, the default, Android also diffs each commit on the JS thread. So updating N siblings with one call each, as JS-driven animations do every frame, costs O(N²) per frame. With `enableSetNativePropsBatching`, `setNativeProps` from JS still records its props in `nativeProps_DEPRECATED` straight away, but queues the node instead of committing it. The first call in a task queues a microtask that commits every queued node in one `cloneMultiple` commit per surface, applying the props the batch set on it at their current values. Committing in a microtask keeps these commits ahead of the observers and mount that follow in the task, as they are when each call commits, and the microtask still runs when the task throws. With `enableFabricCommitBranching`, a React commit earlier in the task replaces the main branch when it's merged, so then the batch is committed on top of React's revision instead. JS reads of the shadow tree commit the queue first. `getShadowTreeRevisionProvider()` returns a provider that does this, which covers `NativeDOM`, the measure methods, `ResizeObserver` and view transitions, and `findNodeAtPoint` and `getRelativeLayoutMetrics` in `UIManagerBinding` do the same. Queueing a microtask needs the `jsi::Runtime`, so the JS callers use a new `setNativeProps_DEPRECATED` overload that takes it. The existing overload is unchanged. Batching is bridgeless only, because bridge mode doesn't drain microtasks (Hermes has no microtask queue there), so with `enableBridgelessArchitecture` off every call still commits. The flag is off by default. Changelog: [Internal]
robhogan
force-pushed
the
robhogan/batch-set-native-props
branch
from
November 28, 2026 02:17
5a7beb5 to
694ee42
Compare
This branch has not been deployed
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.
Summary:
Currently, every
setNativePropscall commits the shadow tree:react-native/packages/react-native/ReactCommon/react/renderer/uimanager/UIManager.cpp
Lines 487 to 514 in 3b49389
That commit clones the node's ancestors, and cloning a parent with a new child list also clones each of its other children (
YogaLayoutableShadowNode::adoptYogaChild). WhileenableAccumulatedUpdatesInRawPropsAndroidis off, Android also diffs each commit on the JS thread. So moving N sibling views with one call each per frame, as JS-driven animations do, is O(N²) per frame.This adds
enableSetNativePropsBatching. With it on,setNativePropsstill records its props innativeProps_DEPRECATEDstraight away, but queues the node, and the first call in a task queues a microtask that commits every queued node in onecloneMultiplecommit per surface, applying the props the batch set on it. Committing in a microtask keeps these commits ahead of observers and the mount later in the task, as they are today, and JS reads of the shadow tree (NativeDOM, the measure methods,findNodeAtPoint,getRelativeLayoutMetrics) commit the queue first. WithenableFabricCommitBranching, a React commit earlier in the task replaces the main branch when it's merged, so then the batch goes on top of React's revision instead. It's bridgeless only, because bridge mode doesn't drain microtasks.One thing changes with the flag on: native code that reads the tree directly, rather than through JS, sees the new props once the microtask has run rather than after each call.
A bouncing-ball stress test in RNTester's Playground (N sibling views, each moved with
setNativePropsevery frame), release builds ofmainand this PR side by side:android-main-vs-pr-public.mp4
ios-main-vs-pr-public.mp4
mainChangelog:
[Internal]
Test Plan:
New Fantom test, run with the flag and
enableFabricCommitBranchingeach on and off:46 tests pass. Its
ResizeObserverand throwing-task tests fail against a version that commits in the rendering update instead of a microtask. With commit branching on, its test for a React update before the call fails without the commit on top of React's revision. Its test with a native-driven animation fails against a version that reapplies every prop ever set throughsetNativeProps, which reverts the animated value.The existing Mounting,
ReactNativeElement, Animated,ResizeObserverandIntersectionObserversuites pass (945 tests).Benchmark (AI-driven): RNTester release builds at
main(3b49389) and this branch with the flag defaulted on, installed side by side, Playground running N absolutely positioned sibling views and onesetNativePropsper view per frame fromrequestAnimationFrame. 200-view figures are medians of 6 interleaved cold launches each, from the app's own 500 ms frame counter after a 6 s warm-up. The iPhone 400-view figures are read from the app's on-screen frame counter in a screen recording (WebDriverAgent, about 18 fps), with capture running. The builds are from an earlier revision of this branch, which applied all of a view's stored native props in each batch rather than only the ones the batch set. Here every call sets all of them, so the work is the same.