|
| 1 | +# Runtime Shadow Node Reference Updates |
| 2 | + |
| 3 | +[🏠 Home](../../../../../../../__docs__/README.md) |
| 4 | + |
| 5 | +The `passChildrenWhenCloningPersistedNodes` feature improves rendering |
| 6 | +performance for use cases where cloning of Shadow Nodes holding a large number |
| 7 | +of children is frequent. A typical example of these are ScrollView components |
| 8 | +holding large lists. The feature improves layout performance by reducing the |
| 9 | +need to invalidate the layout information held by the cloned Shadow Node. |
| 10 | + |
| 11 | +## 🚀 Usage |
| 12 | + |
| 13 | +The features is controlled by the `passChildrenWhenCloningPersistedNodes` flag |
| 14 | +defined in the `ReactNativeInternalFeatureFlags` file. Seeting the feature flag |
| 15 | +before the React renderer is initialized will enable the feature. |
| 16 | + |
| 17 | +## 📐 Design |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +When the React renderer needs to clone a node that represents a host component |
| 22 | +and thus has a corresponding ShadowNode instance, the process follows these |
| 23 | +steps: |
| 24 | + |
| 25 | +- Clone the ShadowNode |
| 26 | +- Traverse the node's descendants to find all first level host components |
| 27 | +- Whenever a host component is seen, append it to the newly cloned ShadowNode |
| 28 | + instance |
| 29 | + |
| 30 | +Most ShadowNode instances hold layout data and are represented by a |
| 31 | +YogaLayoutableShadowNode. These nodes are responsible for keeping the yoga tree |
| 32 | +updated and holding the final layout data for the native view that the |
| 33 | +ShadowNode represents. |
| 34 | + |
| 35 | +Any modification of a YogaLayoutableShadowNode will mark the node as dirty and |
| 36 | +requiring layout when committed. Appending a child node to a |
| 37 | +YogaLayoutableShadowNode is considered as a modification. Meaning that whenever |
| 38 | +the React renderer needs to clone a ShadowNode that has direct children, it will |
| 39 | +be marked as having a dirty layout when the children will be appended back to |
| 40 | +the cloned instance. |
| 41 | + |
| 42 | +The `passChildrenWhenCloningPersistedNodes` feature collects all children that |
| 43 | +need to be appended to the ShadowNode after cloning in a set. This set is being |
| 44 | +passed to the ShadowNode clone call which in turn will append back the nodes |
| 45 | +directly during the cloning. This removes the need to append the children one by |
| 46 | +one after cloning and bypasses the node dirtying that is involved with this type |
| 47 | +of mutation. |
| 48 | + |
| 49 | +The clone implementation of the YogaLayoutableShadowNode will compare the |
| 50 | +previous set of children with the new set. If both sets have the same size and |
| 51 | +each node has equivalent styling, the cloned node is not being dirtied for |
| 52 | +layout. This allows for improving the layout data re-use on subsequent renders. |
0 commit comments