Repository navigation
Avoid copying ShadowViews into Android mount items - #60224
meta-codesync[bot] merged 2 commits into
Conversation
`FabricMountingManager::executeMount` turns every mutation into one or more `CppMountItem`s, and each item stored copies of its old and new `ShadowView`. A copy costs three atomic reference count increments (props, event emitter, state) and three decrements when the item is destroyed, and the item vectors move these ~160-byte structs on every reallocation. `CppMountItem` now holds `const ShadowView&` references instead. The items only exist inside `executeMount`, and the transaction whose mutations they point into is a `const&` parameter that outlives the call and is not modified during it. The empty side of an item binds to a shared static `CppMountItem::emptyShadowView()`. The one modified local copy (the preallocated-props diff on insert) is kept in a `std::deque` local to `executeMount`, whose element addresses are stable. The JNI buffers written are unchanged.
| const EventEmitter* eventEmitter; | ||
| }; | ||
| std::unordered_map<Tag, CreatedView> createdViews; | ||
| std::deque<ShadowView> preallocatedShadowViews; |
There was a problem hiding this comment.
Why a deque instead of a vector?
There was a problem hiding this comment.
The items hold references to the copy, and a vector would move existing elements when it grows and leave those references dangling. dequeue never moves them.
javache
left a comment
There was a problem hiding this comment.
Please document that the MountingTransaction must remain held until the JNI transaction is created, as future experiments may change that assumptiom.
`CppMountItem`s reference the `ShadowView`s in the transaction's mutations, so the transaction must stay alive and unmodified until the `IntBufferBatchMountItem` is created. Today that happens before `executeMount` returns.
Added a comment @javache |
|
@javache has imported this pull request. If you are a Meta employee, you can view this in D133982142. |
Abbondanzo
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
|
This pull request was successfully merged by @riteshshukla04 in 548120a When will my fix make it into a release? | How to file a pick request? |
Summary:
[AI Generated PR] .
The code was written by AI.
While working on some new features in
react-native-release-profiler, I found that building the items, destroying them (~CppMountItem alone was 16.5%) and reallocating the vectors made up about 44% of executeMount using simple perf.So I created a test bench in RN Tester. I created 6*500 view matrix in RN tester . It took
FabricMountingManager::executeMount87ms there.Problem:
FabricMountingManager::executeMountturns each mutation into short-livedCppMountItems, writes them into the JNI buffers, and discards them. Each item copied its old and newShadowView. A copy costs three atomic reference count increments (props, event emitter, state), three decrements on destruction, and ~160-byte moves whenever the item vectors grow. In a release profile on a Galaxy M14, creating, destroying and reallocating these items took ~44% ofexecuteMount. The copies are unnecessary: the views already live in the transaction's mutations, which outlive the call and don't change during it.Fix:
CppMountItemnow storesconst ShadowView&references into the transaction's mutations instead of copies, which removes six atomic reference count updates per view.Items with nothing on one side point at a shared static
emptyShadowView(), and the one modified copy (the preallocated props) lives in a function-localstd::dequeso its address stays stable.Changelog:
[ANDROID] [CHANGED] - FabricMountingManager::executeMount no longer copies ShadowViews into every mount item
Test Plan:
Tested on RN tester
