Skip to content

Commit f71e48d

Browse files
committed
Emit Fabric subtree mount and unmount mutations directly
The Fabric Differentiator writes mount and unmount mutations for whole subtrees directly into the destination list when `enableDirectSubtreeMutations` is enabled. The flag defaults to off. Direct emission avoids allocating and merging a temporary mutation list at each level of the subtree. `ctest --test-dir private/react-native-fantom/build/tester/react-common-tests --output-on-failure -j 10` passes with the flag default off and in a local build with the default on. The regression test runs in both modes. It mounts and unmounts a subtree in which one view forms a stacking context, one view is flattened away, and one view stays in the mounted tree while its children mount in its parent. It compares the results with independently built trees. `yarn fantom packages/react-native/src/private/renderer/mounting/__tests__` passes with the default and with both values of the flag selected by a local `@fantom_flags enableDirectSubtreeMutations:*` override. A single Release C++ binary on Apple M6 uses `proc_pid_rusage` to count retired instructions for diffs of a 341-view tree with four children per parent. For each operation, both flag settings emit the same ordered list of 682 mutations. Across five batches of 1,000 diffs per setting with alternating flag order, the median per mount diff falls from 1,527,412 to 458,622 and the median per unmount diff from 1,526,089 to 457,443. `node scripts/clang-format.js --check`, `yarn flow-check` and `yarn lint` pass, and `yarn featureflags --update` reproduces the generated bindings. Signed-off-by: James Ide <ide@expo.dev>
1 parent 01ec383 commit f71e48d

22 files changed

Lines changed: 422 additions & 103 deletions

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<3c2494d2482efe3dded741dd746d4309>>
7+
* @generated SignedSource<<4578c7d2f792075407fe60bd626e101f>>
88
*/
99

1010
/**
@@ -144,6 +144,12 @@ public object ReactNativeFeatureFlags {
144144
@JvmStatic
145145
public fun enableDestroyShadowTreeRevisionAsync(): Boolean = accessor.enableDestroyShadowTreeRevisionAsync()
146146

147+
/**
148+
* Emits Fabric mount and unmount mutations for whole subtrees directly into the output list.
149+
*/
150+
@JvmStatic
151+
public fun enableDirectSubtreeMutations(): Boolean = accessor.enableDirectSubtreeMutations()
152+
147153
/**
148154
* When enabled a subset of components will avoid double measurement on Android.
149155
*/

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<14682373d73e29327ec3c39882e59af5>>
7+
* @generated SignedSource<<8ff7234e7a77c463c9f2f6109dbf9385>>
88
*/
99

1010
/**
@@ -39,6 +39,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
3939
private var enableCppPropsIteratorSetterCache: Boolean? = null
4040
private var enableCustomFocusSearchOnClippedElementsAndroidCache: Boolean? = null
4141
private var enableDestroyShadowTreeRevisionAsyncCache: Boolean? = null
42+
private var enableDirectSubtreeMutationsCache: Boolean? = null
4243
private var enableDoubleMeasurementFixAndroidCache: Boolean? = null
4344
private var enableEagerRootViewAttachmentCache: Boolean? = null
4445
private var enableExclusivePropsUpdateAndroidCache: Boolean? = null
@@ -294,6 +295,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
294295
return cached
295296
}
296297

298+
override fun enableDirectSubtreeMutations(): Boolean {
299+
var cached = enableDirectSubtreeMutationsCache
300+
if (cached == null) {
301+
cached = ReactNativeFeatureFlagsCxxInterop.enableDirectSubtreeMutations()
302+
enableDirectSubtreeMutationsCache = cached
303+
}
304+
return cached
305+
}
306+
297307
override fun enableDoubleMeasurementFixAndroid(): Boolean {
298308
var cached = enableDoubleMeasurementFixAndroidCache
299309
if (cached == null) {

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<bf090f6eea05b190d2f1ec51e5a0643a>>
7+
* @generated SignedSource<<4fd19a0db046e1ef94007755322f4102>>
88
*/
99

1010
/**
@@ -66,6 +66,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
6666

6767
@DoNotStrip @JvmStatic public external fun enableDestroyShadowTreeRevisionAsync(): Boolean
6868

69+
@DoNotStrip @JvmStatic public external fun enableDirectSubtreeMutations(): Boolean
70+
6971
@DoNotStrip @JvmStatic public external fun enableDoubleMeasurementFixAndroid(): Boolean
7072

7173
@DoNotStrip @JvmStatic public external fun enableEagerRootViewAttachment(): Boolean

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<d7d3d71a9022be2e753263699b3e2ec0>>
7+
* @generated SignedSource<<0fa0c2cc9ef697652bd2ba0518ed61c4>>
88
*/
99

1010
/**
@@ -61,6 +61,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
6161

6262
override fun enableDestroyShadowTreeRevisionAsync(): Boolean = false
6363

64+
override fun enableDirectSubtreeMutations(): Boolean = false
65+
6466
override fun enableDoubleMeasurementFixAndroid(): Boolean = false
6567

6668
override fun enableEagerRootViewAttachment(): Boolean = false

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<d09180773543b2c01eeeced9ec2205a7>>
7+
* @generated SignedSource<<c22772f5ebfd7f594292803a781fde3f>>
88
*/
99

1010
/**
@@ -43,6 +43,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
4343
private var enableCppPropsIteratorSetterCache: Boolean? = null
4444
private var enableCustomFocusSearchOnClippedElementsAndroidCache: Boolean? = null
4545
private var enableDestroyShadowTreeRevisionAsyncCache: Boolean? = null
46+
private var enableDirectSubtreeMutationsCache: Boolean? = null
4647
private var enableDoubleMeasurementFixAndroidCache: Boolean? = null
4748
private var enableEagerRootViewAttachmentCache: Boolean? = null
4849
private var enableExclusivePropsUpdateAndroidCache: Boolean? = null
@@ -317,6 +318,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
317318
return cached
318319
}
319320

321+
override fun enableDirectSubtreeMutations(): Boolean {
322+
var cached = enableDirectSubtreeMutationsCache
323+
if (cached == null) {
324+
cached = currentProvider.enableDirectSubtreeMutations()
325+
accessedFeatureFlags.add("enableDirectSubtreeMutations")
326+
enableDirectSubtreeMutationsCache = cached
327+
}
328+
return cached
329+
}
330+
320331
override fun enableDoubleMeasurementFixAndroid(): Boolean {
321332
var cached = enableDoubleMeasurementFixAndroidCache
322333
if (cached == null) {

‎packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<bedaafe067d7c527f3c3d7b834f31888>>
7+
* @generated SignedSource<<963ee5c8e0c9e5112c1dfaf643d10c2e>>
88
*/
99

1010
/**
@@ -61,6 +61,8 @@ public interface ReactNativeFeatureFlagsProvider {
6161

6262
@DoNotStrip public fun enableDestroyShadowTreeRevisionAsync(): Boolean
6363

64+
@DoNotStrip public fun enableDirectSubtreeMutations(): Boolean
65+
6466
@DoNotStrip public fun enableDoubleMeasurementFixAndroid(): Boolean
6567

6668
@DoNotStrip public fun enableEagerRootViewAttachment(): Boolean

‎packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<b6a5b98eda5fd2c8d06bc3812d85fd18>>
7+
* @generated SignedSource<<cc26bbbcadf2b742ddcbadde9c3ac805>>
88
*/
99

1010
/**
@@ -153,6 +153,12 @@ class ReactNativeFeatureFlagsJavaProvider
153153
return method(javaProvider_);
154154
}
155155

156+
bool enableDirectSubtreeMutations() override {
157+
static const auto method =
158+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableDirectSubtreeMutations");
159+
return method(javaProvider_);
160+
}
161+
156162
bool enableDoubleMeasurementFixAndroid() override {
157163
static const auto method =
158164
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableDoubleMeasurementFixAndroid");
@@ -750,6 +756,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableDestroyShadowTreeRevisionAsync(
750756
return ReactNativeFeatureFlags::enableDestroyShadowTreeRevisionAsync();
751757
}
752758

759+
bool JReactNativeFeatureFlagsCxxInterop::enableDirectSubtreeMutations(
760+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
761+
return ReactNativeFeatureFlags::enableDirectSubtreeMutations();
762+
}
763+
753764
bool JReactNativeFeatureFlagsCxxInterop::enableDoubleMeasurementFixAndroid(
754765
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
755766
return ReactNativeFeatureFlags::enableDoubleMeasurementFixAndroid();
@@ -1253,6 +1264,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
12531264
makeNativeMethod(
12541265
"enableDestroyShadowTreeRevisionAsync",
12551266
JReactNativeFeatureFlagsCxxInterop::enableDestroyShadowTreeRevisionAsync),
1267+
makeNativeMethod(
1268+
"enableDirectSubtreeMutations",
1269+
JReactNativeFeatureFlagsCxxInterop::enableDirectSubtreeMutations),
12561270
makeNativeMethod(
12571271
"enableDoubleMeasurementFixAndroid",
12581272
JReactNativeFeatureFlagsCxxInterop::enableDoubleMeasurementFixAndroid),

‎packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<61b3685bb0e41ac62de7cef4927b577c>>
7+
* @generated SignedSource<<73be3bedd01f8b65b3bb156e2682e90f>>
88
*/
99

1010
/**
@@ -87,6 +87,9 @@ class JReactNativeFeatureFlagsCxxInterop
8787
static bool enableDestroyShadowTreeRevisionAsync(
8888
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
8989

90+
static bool enableDirectSubtreeMutations(
91+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
92+
9093
static bool enableDoubleMeasurementFixAndroid(
9194
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
9295

‎packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<81cd9f64e05f8e5d59eb79c0ecfeda86>>
7+
* @generated SignedSource<<2bdb3b4296a88a176f0c3a1a0d07df23>>
88
*/
99

1010
/**
@@ -102,6 +102,10 @@ bool ReactNativeFeatureFlags::enableDestroyShadowTreeRevisionAsync() {
102102
return getAccessor().enableDestroyShadowTreeRevisionAsync();
103103
}
104104

105+
bool ReactNativeFeatureFlags::enableDirectSubtreeMutations() {
106+
return getAccessor().enableDirectSubtreeMutations();
107+
}
108+
105109
bool ReactNativeFeatureFlags::enableDoubleMeasurementFixAndroid() {
106110
return getAccessor().enableDoubleMeasurementFixAndroid();
107111
}

‎packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<8dca25c44632b8b14c5cdac75a3f36f8>>
7+
* @generated SignedSource<<a725f722bc363dbbff76b5c2d5108636>>
88
*/
99

1010
/**
@@ -136,6 +136,11 @@ class ReactNativeFeatureFlags {
136136
*/
137137
RN_EXPORT static bool enableDestroyShadowTreeRevisionAsync();
138138

139+
/**
140+
* Emits Fabric mount and unmount mutations for whole subtrees directly into the output list.
141+
*/
142+
RN_EXPORT static bool enableDirectSubtreeMutations();
143+
139144
/**
140145
* When enabled a subset of components will avoid double measurement on Android.
141146
*/

0 commit comments

Comments
 (0)