Skip to content

Create StateWrapperImpl from C++ with its state - #59708

Open
tomekzaw wants to merge 1 commit into
react:mainfrom
tomekzaw:state-wrapper-cxx-args
Open

tomekzaw wants to merge 1 commit into
react:mainfrom
tomekzaw:state-wrapper-cxx-args

Conversation

@tomekzaw

@tomekzaw tomekzaw commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

StateWrapperImpl was created with newObjectJavaArgs(). That's a NewObject, whose Java constructor calls back into C++ through initHybrid to create the C++ part. Then cthis() looks that part up again to call setState. The class is only ever created from C++ (its constructor is private), for Create and UpdateState mount items and for preallocation.

It now has a private constructor that takes the state, and those three places create it with newObjectCxxArgs(state), like EventEmitterWrapper. The Java class no longer has initHybrid. The constructor is private, with friend HybridBase, so the public C++ API doesn't change.

Changelog:

[ANDROID] [CHANGED] - Create StateWrapperImpl without a call back from Java

Test Plan:

A Playground screen that mounts 200 Images every 500 ms. Each image gets a StateWrapperImpl when it is preallocated and another one for its UpdateState item. Time per StateWrapperImpl (C++ timer around its creation), and per transaction:

Galaxy A16 Pixel 9a OPPO CPH2269 moto g57 power
One StateWrapperImpl, preallocation 11.04 µs → 7.77 µs (−30%) 936 ns → 732 ns (−22%) 5.71 µs → 4.46 µs (−22%) 8.68 µs → 6.07 µs (−30%)
One StateWrapperImpl, UpdateState item 1.15 µs → 846 ns (−27%) 855 ns → 631 ns (−26%) 4.58 µs → 3.23 µs (−29%) 886 ns → 625 ns (−29%)
executeMount (C++), 200 images 1.84 ms → 1.71 ms (−7%) 1.88 ms → 1.85 ms (no change) 4.99 ms → 5.02 ms (no change) 2.00 ms → 1.86 ms (−7%)

Setup:

  • Release RNTester (./gradlew :packages:rn-tester:android:app:assembleRelease -PreactNativeArchitectures=arm64-v8a, R8 on) with default feature flags, compiled with cmd package compile -m speed.
  • Temporary timing probes, not part of this PR, and a Playground scenario opened by deep link.
  • Each run is a fresh process: a 12 s window after the scenario starts, reported as the median of its samples. Per phone, one discarded run of each build, then 8 A/B/B/A cycles of main and this PR (16 processes per build).
  • Each figure is the median of the 16 processes. A change is shown when its 95% bootstrap confidence interval excludes zero, and "no change" otherwise.
  • The Galaxy A16, Pixel 9a and moto g57 power run Android 16. The OPPO CPH2269 runs Android 11.

yarn cxx-api-validate (Doxygen 1.16.1): all 12 C++ API snapshots match, with no changes needed.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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 Oct 31, 2026
@facebook-github-tools facebook-github-tools Bot added p: Software Mansion Partner: Software Mansion Partner labels Oct 31, 2026
@tomekzaw
tomekzaw marked this pull request as ready for review October 31, 2026 08:22
@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 Oct 31, 2026

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.

1 participant