Commit 52c576b
perf: Write executeMount int buffer to Java in a single JNI call (#58692)
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
Pull Request resolved: #58692
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](https://claude.com/claude-code)
Reviewed By: javache
Differential Revision: D122059662
Pulled By: fabriziocucci
fbshipit-source-id: 60c548755c14d3c07963586215ad53be635870d31 parent 208d445 commit 52c576b
1 file changed
Lines changed: 19 additions & 14 deletions
Lines changed: 19 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
359 | 360 | | |
360 | 361 | | |
361 | 362 | | |
362 | | - | |
363 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
364 | 369 | | |
365 | 370 | | |
366 | | - | |
367 | 371 | | |
368 | 372 | | |
369 | 373 | | |
370 | | - | |
371 | | - | |
| 374 | + | |
372 | 375 | | |
373 | 376 | | |
374 | 377 | | |
375 | 378 | | |
376 | | - | |
377 | | - | |
| 379 | + | |
378 | 380 | | |
379 | 381 | | |
380 | 382 | | |
| |||
862 | 864 | | |
863 | 865 | | |
864 | 866 | | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
| 867 | + | |
870 | 868 | | |
871 | 869 | | |
872 | 870 | | |
| |||
996 | 994 | | |
997 | 995 | | |
998 | 996 | | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
999 | 1004 | | |
1000 | 1005 | | |
1001 | 1006 | | |
| |||
1006 | 1011 | | |
1007 | 1012 | | |
1008 | 1013 | | |
1009 | | - | |
| 1014 | + | |
1010 | 1015 | | |
1011 | 1016 | | |
1012 | 1017 | | |
| |||
1026 | 1031 | | |
1027 | 1032 | | |
1028 | 1033 | | |
1029 | | - | |
| 1034 | + | |
1030 | 1035 | | |
1031 | 1036 | | |
1032 | 1037 | | |
| |||
0 commit comments