Skip to content

Stop walking the shadow tree in UIManager::updateShadowTree once every node is found - #59978

Open
tomekzaw wants to merge 1 commit into
react:mainfrom
tomekzaw:@tomekzaw/update-shadow-tree-early-exit
Open

tomekzaw wants to merge 1 commit into
react:mainfrom
tomekzaw:@tomekzaw/update-shadow-tree-early-exit

Conversation

@tomekzaw

@tomekzaw tomekzaw commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

With cxxNativeAnimatedEnabled, C++ Animated commits animated values into the ShadowTree through UIManager::updateShadowTree on frames that change layout props and on the final frame (NativeAnimatedNodesManagerProvider → MergedValueDispatcher). To find the shadow nodes for the given tags, it walks each surface breadth-first from the root, and it kept walking after every tag had been found. So every call visited every node of the surface, however few views were animating.

The walk now stops as soon as remainingTagToProps is empty. At that point every requested node and its ancestors are already in shadowNodesToUpdate with their depths, so the rest of the tree is never used. The enumeration across surfaces already stops on the same condition; this adds the check inside a surface.

updateShadowTree is on this path when C++ Animated is on and the shared animation backend is off: an app that turns on cxxNativeAnimatedEnabled on 0.88 or 0.89, or the experimental release level on main. The stable release level on main turns on useSharedAnimatedBackend, which commits through AnimationBackend and does not call updateShadowTree.

Not in this PR: shadowNodesToUpdate is de-duplicated with a linear find_if, which is quadratic in the number of updated nodes and their ancestors.

Changelog:

[GENERAL] [CHANGED] - Stop walking the shadow tree in UIManager::updateShadowTree once every requested node has been found

Test Plan:

  • yarn fantom 'Animated-itest|AnimatedComposition-itest|TimingAnimation-itest': 3 suites, 142 tests passed. Fantom enables cxxNativeAnimatedEnabled, and Animated-itest runs with useSharedAnimatedBackend both off and on; with it off, native-driven animations commit through updateShadowTree.

Benchmarks

RNTester release builds of this branch with and without the change, on real phones. Both builds turn on C++ Animated with useSharedAnimatedBackend off. The screen has 1,000 static views and 10 views whose opacity is animated with the native driver; every finished animation commits through updateShadowTree. Medians of a timer around updateShadowTree, 6 rounds of 20 s per scenario, alternating order:

Phone Animated views early in the tree Animated views at the end of the tree
Pixel 9a 4,304 → 2,573 µs (−40%), 1,068 → 18 nodes visited 9,959 → 9,814 µs (−1%), 1,070 nodes visited
moto g57 power 7,996 → 6,274 µs (−22%), 1,090 → 28 nodes visited 26,441 → 26,174 µs (−1%), 1,092 nodes visited
OPPO CPH2269 5,277 → 3,661 µs (−31%), 1,090 → 28 nodes visited 12,889 → 13,550 µs (+5%), 1,092 nodes visited
Galaxy A16 6,675 → 5,444 µs (−18%), 1,068 → 18 nodes visited 14,347 → 14,421 µs (+1%), 1,070 nodes visited
  • The timer also covers cloning and committing, which this PR does not change.
  • With the animated views last, both builds visit the same nodes, so the −1% to +5% there is noise.
  • iPhone numbers are pending.

🤖 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 12, 2026
@facebook-github-tools facebook-github-tools Bot added p: Software Mansion Partner: Software Mansion Partner labels Nov 12, 2026
@tomekzaw

Copy link
Copy Markdown
Contributor Author

cc @bartlomiejbloniarz

@tomekzaw
tomekzaw marked this pull request as ready for review November 12, 2026 16:34
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 12, 2026
@meta-codesync

meta-codesync Bot commented Nov 13, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D131743138.

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 Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants