Skip to content

Commit 3ed9be4

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Pre-allocate mutation vectors in Differentiator to reduce reallocation overhead
Summary: Changelog: [Internal] speed up differentiator | Test | Before (ms) | After (ms) | Improvement | |-------------------------------|-------------|------------|-------------| | 100 uncollapsable views | 3.0 | 2.7 | +10% | | 1000 uncollapsable views | 91.1 | 50.5 | +45% | | 100 views w/ many props | 9.8 | 9.2 | +6% | | 1000 views w/ many props | 147.4 | 116.7 | +21% | | 1500 views w/ many props | 143.1 | 136.7 | +5% | Differential Revision: D94096006
1 parent 4d96fb5 commit 3ed9be4

21 files changed

+240
-87
lines changed

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<<477777b9a795b57f3bb3eaeb030738a9>>
7+
* @generated SignedSource<<22cf2dd60587b906939f2774d416f035>>
88
*/
99

1010
/**
@@ -138,6 +138,12 @@ public object ReactNativeFeatureFlags {
138138
@JvmStatic
139139
public fun enableCustomFocusSearchOnClippedElementsAndroid(): Boolean = accessor.enableCustomFocusSearchOnClippedElementsAndroid()
140140

141+
/**
142+
* Pre-allocate mutation vectors in the Differentiator to reduce reallocation overhead during shadow view diffing.
143+
*/
144+
@JvmStatic
145+
public fun enableDifferentiatorMutationVectorPreallocation(): Boolean = accessor.enableDifferentiatorMutationVectorPreallocation()
146+
141147
/**
142148
* Enables destructor calls for ShadowTreeRevision in the background to reduce UI thread work.
143149
*/

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<<c7b6ea7f1672df7bb3396375378784c5>>
7+
* @generated SignedSource<<7af3aa99f498c613b30359a17b5577eb>>
88
*/
99

1010
/**
@@ -38,6 +38,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
3838
private var enableBridgelessArchitectureCache: Boolean? = null
3939
private var enableCppPropsIteratorSetterCache: Boolean? = null
4040
private var enableCustomFocusSearchOnClippedElementsAndroidCache: Boolean? = null
41+
private var enableDifferentiatorMutationVectorPreallocationCache: Boolean? = null
4142
private var enableDestroyShadowTreeRevisionAsyncCache: Boolean? = null
4243
private var enableDoubleMeasurementFixAndroidCache: Boolean? = null
4344
private var enableEagerMainQueueModulesOnIOSCache: Boolean? = null
@@ -267,6 +268,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
267268
return cached
268269
}
269270

271+
override fun enableDifferentiatorMutationVectorPreallocation(): Boolean {
272+
var cached = enableDifferentiatorMutationVectorPreallocationCache
273+
if (cached == null) {
274+
cached = ReactNativeFeatureFlagsCxxInterop.enableDifferentiatorMutationVectorPreallocation()
275+
enableDifferentiatorMutationVectorPreallocationCache = cached
276+
}
277+
return cached
278+
}
279+
270280
override fun enableDestroyShadowTreeRevisionAsync(): Boolean {
271281
var cached = enableDestroyShadowTreeRevisionAsyncCache
272282
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<<ec036cff49622b8c2b52d2f9eaa59e6c>>
7+
* @generated SignedSource<<8b47d3a231a37a3d4a7b89a74a5a0122>>
88
*/
99

1010
/**
@@ -64,6 +64,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
6464

6565
@DoNotStrip @JvmStatic public external fun enableCustomFocusSearchOnClippedElementsAndroid(): Boolean
6666

67+
@DoNotStrip @JvmStatic public external fun enableDifferentiatorMutationVectorPreallocation(): Boolean
68+
6769
@DoNotStrip @JvmStatic public external fun enableDestroyShadowTreeRevisionAsync(): Boolean
6870

6971
@DoNotStrip @JvmStatic public external fun enableDoubleMeasurementFixAndroid(): 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<<523e3c35d4bd1fc85f2a3bb26b8aad3f>>
7+
* @generated SignedSource<<54932f95b0a9cf0483a2bc03b3d3cc74>>
88
*/
99

1010
/**
@@ -59,6 +59,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
5959

6060
override fun enableCustomFocusSearchOnClippedElementsAndroid(): Boolean = true
6161

62+
override fun enableDifferentiatorMutationVectorPreallocation(): Boolean = false
63+
6264
override fun enableDestroyShadowTreeRevisionAsync(): Boolean = false
6365

6466
override fun enableDoubleMeasurementFixAndroid(): 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<<cfd6a4514be320519a57566182b73f69>>
7+
* @generated SignedSource<<70a43edd653ba85c3885af1e13e9fb95>>
88
*/
99

1010
/**
@@ -42,6 +42,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
4242
private var enableBridgelessArchitectureCache: Boolean? = null
4343
private var enableCppPropsIteratorSetterCache: Boolean? = null
4444
private var enableCustomFocusSearchOnClippedElementsAndroidCache: Boolean? = null
45+
private var enableDifferentiatorMutationVectorPreallocationCache: Boolean? = null
4546
private var enableDestroyShadowTreeRevisionAsyncCache: Boolean? = null
4647
private var enableDoubleMeasurementFixAndroidCache: Boolean? = null
4748
private var enableEagerMainQueueModulesOnIOSCache: Boolean? = null
@@ -289,6 +290,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
289290
return cached
290291
}
291292

293+
override fun enableDifferentiatorMutationVectorPreallocation(): Boolean {
294+
var cached = enableDifferentiatorMutationVectorPreallocationCache
295+
if (cached == null) {
296+
cached = currentProvider.enableDifferentiatorMutationVectorPreallocation()
297+
accessedFeatureFlags.add("enableDifferentiatorMutationVectorPreallocation")
298+
enableDifferentiatorMutationVectorPreallocationCache = cached
299+
}
300+
return cached
301+
}
302+
292303
override fun enableDestroyShadowTreeRevisionAsync(): Boolean {
293304
var cached = enableDestroyShadowTreeRevisionAsyncCache
294305
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<<bbaa4d1498f606886341d34a62acb508>>
7+
* @generated SignedSource<<6a40e5cbecff645336f690a95d1684fd>>
88
*/
99

1010
/**
@@ -59,6 +59,8 @@ public interface ReactNativeFeatureFlagsProvider {
5959

6060
@DoNotStrip public fun enableCustomFocusSearchOnClippedElementsAndroid(): Boolean
6161

62+
@DoNotStrip public fun enableDifferentiatorMutationVectorPreallocation(): Boolean
63+
6264
@DoNotStrip public fun enableDestroyShadowTreeRevisionAsync(): Boolean
6365

6466
@DoNotStrip public fun enableDoubleMeasurementFixAndroid(): 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<<45063df01d7ce8726b4a7d901f1b3341>>
7+
* @generated SignedSource<<736f0da032f0d0e61e88a2268b071716>>
88
*/
99

1010
/**
@@ -147,6 +147,12 @@ class ReactNativeFeatureFlagsJavaProvider
147147
return method(javaProvider_);
148148
}
149149

150+
bool enableDifferentiatorMutationVectorPreallocation() override {
151+
static const auto method =
152+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableDifferentiatorMutationVectorPreallocation");
153+
return method(javaProvider_);
154+
}
155+
150156
bool enableDestroyShadowTreeRevisionAsync() override {
151157
static const auto method =
152158
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableDestroyShadowTreeRevisionAsync");
@@ -637,6 +643,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableCustomFocusSearchOnClippedElement
637643
return ReactNativeFeatureFlags::enableCustomFocusSearchOnClippedElementsAndroid();
638644
}
639645

646+
bool JReactNativeFeatureFlagsCxxInterop::enableDifferentiatorMutationVectorPreallocation(
647+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
648+
return ReactNativeFeatureFlags::enableDifferentiatorMutationVectorPreallocation();
649+
}
650+
640651
bool JReactNativeFeatureFlagsCxxInterop::enableDestroyShadowTreeRevisionAsync(
641652
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
642653
return ReactNativeFeatureFlags::enableDestroyShadowTreeRevisionAsync();
@@ -1052,6 +1063,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
10521063
makeNativeMethod(
10531064
"enableCustomFocusSearchOnClippedElementsAndroid",
10541065
JReactNativeFeatureFlagsCxxInterop::enableCustomFocusSearchOnClippedElementsAndroid),
1066+
makeNativeMethod(
1067+
"enableDifferentiatorMutationVectorPreallocation",
1068+
JReactNativeFeatureFlagsCxxInterop::enableDifferentiatorMutationVectorPreallocation),
10551069
makeNativeMethod(
10561070
"enableDestroyShadowTreeRevisionAsync",
10571071
JReactNativeFeatureFlagsCxxInterop::enableDestroyShadowTreeRevisionAsync),

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<<5ac93ed057017f8d1a388b8029614f18>>
7+
* @generated SignedSource<<ca1ca3ebd21aca34c80512e829027dc9>>
88
*/
99

1010
/**
@@ -84,6 +84,9 @@ class JReactNativeFeatureFlagsCxxInterop
8484
static bool enableCustomFocusSearchOnClippedElementsAndroid(
8585
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
8686

87+
static bool enableDifferentiatorMutationVectorPreallocation(
88+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
89+
8790
static bool enableDestroyShadowTreeRevisionAsync(
8891
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
8992

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<<9d81f74c5926706ee353813e594575e8>>
7+
* @generated SignedSource<<89d14fa7c51ca92ab1c42f5bc1e18bae>>
88
*/
99

1010
/**
@@ -98,6 +98,10 @@ bool ReactNativeFeatureFlags::enableCustomFocusSearchOnClippedElementsAndroid()
9898
return getAccessor().enableCustomFocusSearchOnClippedElementsAndroid();
9999
}
100100

101+
bool ReactNativeFeatureFlags::enableDifferentiatorMutationVectorPreallocation() {
102+
return getAccessor().enableDifferentiatorMutationVectorPreallocation();
103+
}
104+
101105
bool ReactNativeFeatureFlags::enableDestroyShadowTreeRevisionAsync() {
102106
return getAccessor().enableDestroyShadowTreeRevisionAsync();
103107
}

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<<84e2800073ffab2313a4e27897c0c246>>
7+
* @generated SignedSource<<97f4abf7e573a97e54b3e9c2473226ec>>
88
*/
99

1010
/**
@@ -129,6 +129,11 @@ class ReactNativeFeatureFlags {
129129
*/
130130
RN_EXPORT static bool enableCustomFocusSearchOnClippedElementsAndroid();
131131

132+
/**
133+
* Pre-allocate mutation vectors in the Differentiator to reduce reallocation overhead during shadow view diffing.
134+
*/
135+
RN_EXPORT static bool enableDifferentiatorMutationVectorPreallocation();
136+
132137
/**
133138
* Enables destructor calls for ShadowTreeRevision in the background to reduce UI thread work.
134139
*/

0 commit comments

Comments
 (0)