Skip to content

perf: copy each animated props object once in collectProps - #10706

Open
pawicao wants to merge 2 commits into
mainfrom
@pawicao/collect-props-single-copy
Open

pawicao wants to merge 2 commits into
mainfrom
@pawicao/collect-props-single-copy

Conversation

@pawicao

@pawicao pawicao commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Note

This pull request was authored by AI on behalf of @pawicao.

Summary

UpdatesRegistry::collectProps runs under the registry lock in every React commit hook and in every registry flush, and the UI thread takes the same lock on each frame. It copied each animated props object three times: it copied the whole registry map, then each value into RawProps, then the new vector into the props map. The map copy dates from before the function asserted the lock, so it protected nothing. I dropped it and emplace each value into the props map directly, so each value is copied once and the order of values per family stays the same. I also made the function const, because it now only reads the registry.

Test plan

Release build on a Pixel 9a, a React commit every 100 ms over N animated views, sync props off, DISABLE_COMMIT_PAUSING_MECHANISM: true, 4 runs per build in ABBA order, measured on top of #10631 (median):

N = 500 before N = 500 after N = 1500 before N = 1500 after
collectProps p50 1.62 ms 0.49 ms 6.31 ms 2.56 ms
commit hook lock hold p50 10.0 ms 9.2 ms 32.5 ms 29.1 ms
UI frames per 20 s 640 663 140 149

Changelog

  • I added a changelog fragment with yarn changelog:add for each changed package, or this PR does not change react-native-reanimated or react-native-worklets.

`UpdatesRegistry::collectProps` runs under the registry lock. It copied
the whole registry map, then each value into `RawProps`, then the new
vector into the props map. It now copies each value once, in the same
order for each family.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1052fc8a-7d73-4a8d-b33d-ca8e67a6d16d
📥 Commits

Reviewing files that changed from the base of the PR and between 835f656 and 86400bf.

📒 Files selected for processing: 2
  • packages/react-native-reanimated/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.cpp
  • packages/react-native-reanimated/Common/cpp/reanimated/Fabric/updates/UpdatesRegistry.h

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

UpdatesRegistry::collectProps is now declared and implemented as a const method. It iterates updatesRegistry_ directly and appends a props value to the vector for each shadowNodeFamily in propsMap. The changelog records reduced registry-lock time while collecting animated values for a commit.

Priority: ➖ Normal

Change: Refactor

Merge Risk: ⚪ Minimal · up to 86400

The change reduces copying during animated-props collection. The checked ordering concern does not alter per-family precedence, and no current merge-blocking behavior is established.

Pre-merge checks: Passed 4
Check name Status Explanation
Description check Passed The description directly explains the collectProps performance change, const qualification, copy reduction, and test results.
Title check Passed The title clearly and concisely identifies the main performance change: copying each animated props object once in collectProps.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@BruceBotterson BruceBotterson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found no problems.

  1. The removed copy of updatesRegistry_ protected nothing: the caller must hold the manager lock (assert at UpdatesRegistry.cpp:185), both callers do (UpdatesRegistryManager.cpp:100-107, ReanimatedModuleProxy.cpp:798), and the loop does not change the registry.
  2. emplace_back(props) compiles with the explicit RawProps(folly::dynamic) constructor. Each folly::dynamic is still copied once per entry.
  3. operator[] gives the same PropsMap contents as the old find-or-emplace code.
  4. const is safe: collectProps is not virtual.
  5. The changelog fragment holds one sentence.

@pawicao
pawicao marked this pull request as ready for review October 19, 2026 12:51
@pawicao
pawicao requested a review from tshmieldev October 19, 2026 12:55

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants