Skip to content

Commit 89784ba

Browse files
sammy-SCzoontek
authored andcommitted
Pre-allocate mutation vectors in Differentiator to reduce reallocation overhead (facebook#55819)
Summary: Pull Request resolved: facebook#55819 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% | Reviewed By: mdvacca Differential Revision: D94096006 fbshipit-source-id: 024072e12fc7ba7969ce0ca6969ba8895f38ea15
1 parent 918398e commit 89784ba

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<<156d4f5f35037184b6fc61ff1d856028>>
7+
* @generated SignedSource<<2ca6b65f1103a486e4e5a006de629e76>>
88
*/
99

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

147+
/**
148+
* Pre-allocate mutation vectors in the Differentiator to reduce reallocation overhead during shadow view diffing.
149+
*/
150+
@JvmStatic
151+
public fun enableDifferentiatorMutationVectorPreallocation(): Boolean = accessor.enableDifferentiatorMutationVectorPreallocation()
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<<0875d5e54d884a26d37bb4eb2acc57d5>>
7+
* @generated SignedSource<<202662ab1c26ed104cfe837162d4f9a2>>
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 enableDifferentiatorMutationVectorPreallocationCache: Boolean? = null
4243
private var enableDoubleMeasurementFixAndroidCache: Boolean? = null
4344
private var enableEagerMainQueueModulesOnIOSCache: Boolean? = null
4445
private var enableEagerRootViewAttachmentCache: Boolean? = null
@@ -277,6 +278,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
277278
return cached
278279
}
279280

281+
override fun enableDifferentiatorMutationVectorPreallocation(): Boolean {
282+
var cached = enableDifferentiatorMutationVectorPreallocationCache
283+
if (cached == null) {
284+
cached = ReactNativeFeatureFlagsCxxInterop.enableDifferentiatorMutationVectorPreallocation()
285+
enableDifferentiatorMutationVectorPreallocationCache = cached
286+
}
287+
return cached
288+
}
289+
280290
override fun enableDoubleMeasurementFixAndroid(): Boolean {
281291
var cached = enableDoubleMeasurementFixAndroidCache
282292
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<<948a9beebe2ff00791a03455eb774eee>>
7+
* @generated SignedSource<<03f5b76fefda14757a43414f6624601a>>
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 enableDifferentiatorMutationVectorPreallocation(): Boolean
70+
6971
@DoNotStrip @JvmStatic public external fun enableDoubleMeasurementFixAndroid(): Boolean
7072

7173
@DoNotStrip @JvmStatic public external fun enableEagerMainQueueModulesOnIOS(): 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<<89c61520177334f93c65ff92c2fc74a6>>
7+
* @generated SignedSource<<7713ee7b0947f0ae8c66b73413a7f226>>
88
*/
99

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

6262
override fun enableDestroyShadowTreeRevisionAsync(): Boolean = false
6363

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

6668
override fun enableEagerMainQueueModulesOnIOS(): 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<<669708c311abe9ffc8f7783219e2baad>>
7+
* @generated SignedSource<<79cf67c605a76059f010cf2ccd0ec64b>>
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 enableDifferentiatorMutationVectorPreallocationCache: Boolean? = null
4647
private var enableDoubleMeasurementFixAndroidCache: Boolean? = null
4748
private var enableEagerMainQueueModulesOnIOSCache: Boolean? = null
4849
private var enableEagerRootViewAttachmentCache: Boolean? = null
@@ -300,6 +301,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
300301
return cached
301302
}
302303

304+
override fun enableDifferentiatorMutationVectorPreallocation(): Boolean {
305+
var cached = enableDifferentiatorMutationVectorPreallocationCache
306+
if (cached == null) {
307+
cached = currentProvider.enableDifferentiatorMutationVectorPreallocation()
308+
accessedFeatureFlags.add("enableDifferentiatorMutationVectorPreallocation")
309+
enableDifferentiatorMutationVectorPreallocationCache = cached
310+
}
311+
return cached
312+
}
313+
303314
override fun enableDoubleMeasurementFixAndroid(): Boolean {
304315
var cached = enableDoubleMeasurementFixAndroidCache
305316
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<<db06b64a8d1b9ab99b368fea41185d62>>
7+
* @generated SignedSource<<655d1ff3caeb3d8e95d44176d65b951b>>
88
*/
99

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

6262
@DoNotStrip public fun enableDestroyShadowTreeRevisionAsync(): Boolean
6363

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

6668
@DoNotStrip public fun enableEagerMainQueueModulesOnIOS(): 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<<0b95d68522d63d51d3e524aeecff246a>>
7+
* @generated SignedSource<<175e48107d9bd1d713a4da0a252a58bf>>
88
*/
99

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

156+
bool enableDifferentiatorMutationVectorPreallocation() override {
157+
static const auto method =
158+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableDifferentiatorMutationVectorPreallocation");
159+
return method(javaProvider_);
160+
}
161+
156162
bool enableDoubleMeasurementFixAndroid() override {
157163
static const auto method =
158164
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableDoubleMeasurementFixAndroid");
@@ -648,6 +654,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableDestroyShadowTreeRevisionAsync(
648654
return ReactNativeFeatureFlags::enableDestroyShadowTreeRevisionAsync();
649655
}
650656

657+
bool JReactNativeFeatureFlagsCxxInterop::enableDifferentiatorMutationVectorPreallocation(
658+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
659+
return ReactNativeFeatureFlags::enableDifferentiatorMutationVectorPreallocation();
660+
}
661+
651662
bool JReactNativeFeatureFlagsCxxInterop::enableDoubleMeasurementFixAndroid(
652663
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
653664
return ReactNativeFeatureFlags::enableDoubleMeasurementFixAndroid();
@@ -1066,6 +1077,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
10661077
makeNativeMethod(
10671078
"enableDestroyShadowTreeRevisionAsync",
10681079
JReactNativeFeatureFlagsCxxInterop::enableDestroyShadowTreeRevisionAsync),
1080+
makeNativeMethod(
1081+
"enableDifferentiatorMutationVectorPreallocation",
1082+
JReactNativeFeatureFlagsCxxInterop::enableDifferentiatorMutationVectorPreallocation),
10691083
makeNativeMethod(
10701084
"enableDoubleMeasurementFixAndroid",
10711085
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<<6b7e2af51ba9d64ae4e474dfa104a7c3>>
7+
* @generated SignedSource<<e182e4c23748be5ade70f6568ea2046f>>
88
*/
99

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

90+
static bool enableDifferentiatorMutationVectorPreallocation(
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<<08a361f2ffac6a0496adac1d4c3e4726>>
7+
* @generated SignedSource<<5208616bc5d84f040ad0fa5e85acd6c4>>
88
*/
99

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

105+
bool ReactNativeFeatureFlags::enableDifferentiatorMutationVectorPreallocation() {
106+
return getAccessor().enableDifferentiatorMutationVectorPreallocation();
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<<0bbe4d41581432dfad7adbc2db133d00>>
7+
* @generated SignedSource<<1cbe2158c5242b2980ddafafe9084d7c>>
88
*/
99

1010
/**
@@ -134,6 +134,11 @@ class ReactNativeFeatureFlags {
134134
*/
135135
RN_EXPORT static bool enableDestroyShadowTreeRevisionAsync();
136136

137+
/**
138+
* Pre-allocate mutation vectors in the Differentiator to reduce reallocation overhead during shadow view diffing.
139+
*/
140+
RN_EXPORT static bool enableDifferentiatorMutationVectorPreallocation();
141+
137142
/**
138143
* When enabled a subset of components will avoid double measurement on Android.
139144
*/

0 commit comments

Comments
 (0)