Skip to content

perf: Write executeMount int buffer to Java in a single JNI call - #58692

Open
shubh73 wants to merge 1 commit into
react:mainfrom
shubh73:perf/fabric-mount-int-batching
Open

shubh73 wants to merge 1 commit into
react:mainfrom
shubh73:perf/fabric-mount-int-batching

Conversation

@shubh73

@shubh73 shubh73 commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

FabricMountingManager::executeMount wrote the int buffer to Java with one SetIntArrayRegion per writeInt/writeIntArray, which is ~4.5k JNI calls for a commit that mounts 1500 views. The exact size is already known from computeBufferSizes, so this fills a std::vector<jint> instead and copies it once before createIntBufferBatchMountItem. The int[] Java receives is identical.

GetPrimitiveArrayCritical isn't an option here since the object writes call into Java between int writes, and on ART GetIntArrayElements copies movable arrays anyway.

Time spent in executeMount for one commit on an OPPO CPH2667 (Dimensity 6300, Android 16), release build. Each cell is the median over 114 commits from 6 interleaved runs:

Commit JNI calls Before After Change
Remove 1500 views 3004 → 1 2.14 ms 1.88 ms −12%
Add 1500 views 4505 → 1 4.06 ms 3.86 ms −5%
Restyle 1500 views (size, padding, color) 4505 → 1 5.25 ms 5.04 ms −4%

The slowest commits improve more (e.g. 19.6 → 6.4 ms when restyling). The int transfer on its own goes from 174 → 87 µs per 1500-view commit. On an Apple silicon emulator JNI calls are ~5x cheaper and the difference is within noise.

Changelog:

[ANDROID] [CHANGED] - Write Fabric mount instruction ints to Java in a single JNI call

Test Plan:

  • Built a variant that also fills a shadow int[] the old way and compares it with the array sent to Java on every commit: 1390 commits on device and 782 on emulator across Playground (1500 views), FlatList, Text and Image, 0 mismatches.
  • RNTester (yarn android and release) on device and emulator: Playground, FlatList, Text and Image render as before.
  • yarn lint, yarn flow-check, yarn format-check-cpp pass.
  • Couldn't run FabricMountingManagerTest / FabricMountingManagerInstrumentationTest, they're Buck-only.

🤖 Generated with Claude Code

executeMount called SetIntArrayRegion for every writeInt/writeIntArray,
~4.5k JNI calls for a commit mounting 1500 views. The exact size is already
known from computeBufferSizes, so fill a std::vector<jint> and copy it once
before createIntBufferBatchMountItem. The int[] Java receives is unchanged.

Changelog: [ANDROID] [CHANGED] - Write Fabric mount instruction ints to Java in a single JNI call

Co-Authored-By: Claude Opus 5.5 (1M context) <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 Sep 26, 2026
@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 Sep 26, 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. 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