Skip to content

Commit d2bbd5a

Browse files
Nick Lefevermeta-codesync[bot]
authored andcommitted
Add feature flag to disable view preallocation (#54442)
Summary: Pull Request resolved: #54442 Add a feature flag to disable view preallocation on Android Changelog: [Internal] Reviewed By: javache, christophpurrer Differential Revision: D86488124 fbshipit-source-id: 2c345ef366bf9e0448cadc6abbbfd6c0a9ce0f8a
1 parent cc3859f commit d2bbd5a

22 files changed

+214
-93
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ public void doFrameGuarded(long frameTimeNanos) {
14851485
mBinding.driveCxxAnimations();
14861486
}
14871487

1488-
if (mBinding != null) {
1488+
if (!ReactNativeFeatureFlags.disableViewPreallocationAndroid() && mBinding != null) {
14891489
mBinding.drainPreallocateViewsQueue();
14901490
}
14911491

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<<9646ebeba75ec903be5ade7e2333f0c8>>
7+
* @generated SignedSource<<aa1ec8f536bf908fc0f0eebd0a57b588>>
88
*/
99

1010
/**
@@ -90,6 +90,12 @@ public object ReactNativeFeatureFlags {
9090
@JvmStatic
9191
public fun disableTextLayoutManagerCacheAndroid(): Boolean = accessor.disableTextLayoutManagerCacheAndroid()
9292

93+
/**
94+
* Force disable view preallocation triggered from createNode off the main thread on Android
95+
*/
96+
@JvmStatic
97+
public fun disableViewPreallocationAndroid(): Boolean = accessor.disableViewPreallocationAndroid()
98+
9399
/**
94100
* When enabled, the accessibilityOrder prop will propagate to native platforms and define the accessibility order.
95101
*/

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<<9d6ccbe6d02608901fc18ad88baab176>>
7+
* @generated SignedSource<<5b0e5a1580c8fd30101840b89e35e736>>
88
*/
99

1010
/**
@@ -30,6 +30,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
3030
private var disableOldAndroidAttachmentMetricsWorkaroundsCache: Boolean? = null
3131
private var disableSubviewClippingAndroidCache: Boolean? = null
3232
private var disableTextLayoutManagerCacheAndroidCache: Boolean? = null
33+
private var disableViewPreallocationAndroidCache: Boolean? = null
3334
private var enableAccessibilityOrderCache: Boolean? = null
3435
private var enableAccumulatedUpdatesInRawPropsAndroidCache: Boolean? = null
3536
private var enableAndroidLinearTextCache: Boolean? = null
@@ -193,6 +194,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
193194
return cached
194195
}
195196

197+
override fun disableViewPreallocationAndroid(): Boolean {
198+
var cached = disableViewPreallocationAndroidCache
199+
if (cached == null) {
200+
cached = ReactNativeFeatureFlagsCxxInterop.disableViewPreallocationAndroid()
201+
disableViewPreallocationAndroidCache = cached
202+
}
203+
return cached
204+
}
205+
196206
override fun enableAccessibilityOrder(): Boolean {
197207
var cached = enableAccessibilityOrderCache
198208
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<<fbc551ca005a7d8abcd2cf2e5d29a3a6>>
7+
* @generated SignedSource<<00737feba90fb1ffbd9c4e7c2b83a239>>
88
*/
99

1010
/**
@@ -48,6 +48,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
4848

4949
@DoNotStrip @JvmStatic public external fun disableTextLayoutManagerCacheAndroid(): Boolean
5050

51+
@DoNotStrip @JvmStatic public external fun disableViewPreallocationAndroid(): Boolean
52+
5153
@DoNotStrip @JvmStatic public external fun enableAccessibilityOrder(): Boolean
5254

5355
@DoNotStrip @JvmStatic public external fun enableAccumulatedUpdatesInRawPropsAndroid(): 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<<7b8a5ad9a3353ea32a39bd139e9174f7>>
7+
* @generated SignedSource<<4b918bb9e7d4d920844e1059894723c4>>
88
*/
99

1010
/**
@@ -43,6 +43,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
4343

4444
override fun disableTextLayoutManagerCacheAndroid(): Boolean = false
4545

46+
override fun disableViewPreallocationAndroid(): Boolean = false
47+
4648
override fun enableAccessibilityOrder(): Boolean = false
4749

4850
override fun enableAccumulatedUpdatesInRawPropsAndroid(): 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<<9bb9a7cf89c92f5a397b2328fa983dc6>>
7+
* @generated SignedSource<<53a55696d6897c5bf0ce8b5389d4c7f9>>
88
*/
99

1010
/**
@@ -34,6 +34,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
3434
private var disableOldAndroidAttachmentMetricsWorkaroundsCache: Boolean? = null
3535
private var disableSubviewClippingAndroidCache: Boolean? = null
3636
private var disableTextLayoutManagerCacheAndroidCache: Boolean? = null
37+
private var disableViewPreallocationAndroidCache: Boolean? = null
3738
private var enableAccessibilityOrderCache: Boolean? = null
3839
private var enableAccumulatedUpdatesInRawPropsAndroidCache: Boolean? = null
3940
private var enableAndroidLinearTextCache: Boolean? = null
@@ -207,6 +208,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
207208
return cached
208209
}
209210

211+
override fun disableViewPreallocationAndroid(): Boolean {
212+
var cached = disableViewPreallocationAndroidCache
213+
if (cached == null) {
214+
cached = currentProvider.disableViewPreallocationAndroid()
215+
accessedFeatureFlags.add("disableViewPreallocationAndroid")
216+
disableViewPreallocationAndroidCache = cached
217+
}
218+
return cached
219+
}
220+
210221
override fun enableAccessibilityOrder(): Boolean {
211222
var cached = enableAccessibilityOrderCache
212223
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<<eeb5d70e45eecdef0d9307cbe8ff17c2>>
7+
* @generated SignedSource<<f8c3a4173b151b4560aa2f98e3969ff1>>
88
*/
99

1010
/**
@@ -43,6 +43,8 @@ public interface ReactNativeFeatureFlagsProvider {
4343

4444
@DoNotStrip public fun disableTextLayoutManagerCacheAndroid(): Boolean
4545

46+
@DoNotStrip public fun disableViewPreallocationAndroid(): Boolean
47+
4648
@DoNotStrip public fun enableAccessibilityOrder(): Boolean
4749

4850
@DoNotStrip public fun enableAccumulatedUpdatesInRawPropsAndroid(): Boolean

packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricUIManagerBinding.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,10 @@ void FabricUIManagerBinding::schedulerShouldRenderTransactions(
672672

673673
void FabricUIManagerBinding::schedulerDidRequestPreliminaryViewAllocation(
674674
const ShadowNode& shadowNode) {
675+
if (ReactNativeFeatureFlags::disableViewPreallocationAndroid()) {
676+
return;
677+
}
678+
675679
auto mountingManager = getMountingManager("preallocateView");
676680
if (!mountingManager) {
677681
return;

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<<0527dbb4a838be34b80d76b11d18cea0>>
7+
* @generated SignedSource<<f5be088886181124b1b9bb1b59222689>>
88
*/
99

1010
/**
@@ -99,6 +99,12 @@ class ReactNativeFeatureFlagsJavaProvider
9999
return method(javaProvider_);
100100
}
101101

102+
bool disableViewPreallocationAndroid() override {
103+
static const auto method =
104+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("disableViewPreallocationAndroid");
105+
return method(javaProvider_);
106+
}
107+
102108
bool enableAccessibilityOrder() override {
103109
static const auto method =
104110
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableAccessibilityOrder");
@@ -585,6 +591,11 @@ bool JReactNativeFeatureFlagsCxxInterop::disableTextLayoutManagerCacheAndroid(
585591
return ReactNativeFeatureFlags::disableTextLayoutManagerCacheAndroid();
586592
}
587593

594+
bool JReactNativeFeatureFlagsCxxInterop::disableViewPreallocationAndroid(
595+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
596+
return ReactNativeFeatureFlags::disableViewPreallocationAndroid();
597+
}
598+
588599
bool JReactNativeFeatureFlagsCxxInterop::enableAccessibilityOrder(
589600
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
590601
return ReactNativeFeatureFlags::enableAccessibilityOrder();
@@ -1006,6 +1017,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
10061017
makeNativeMethod(
10071018
"disableTextLayoutManagerCacheAndroid",
10081019
JReactNativeFeatureFlagsCxxInterop::disableTextLayoutManagerCacheAndroid),
1020+
makeNativeMethod(
1021+
"disableViewPreallocationAndroid",
1022+
JReactNativeFeatureFlagsCxxInterop::disableViewPreallocationAndroid),
10091023
makeNativeMethod(
10101024
"enableAccessibilityOrder",
10111025
JReactNativeFeatureFlagsCxxInterop::enableAccessibilityOrder),

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<<a1deb0145d8c51d608903e1704e96b8d>>
7+
* @generated SignedSource<<52c23431c548b29c9a5566e79f2bd7f7>>
88
*/
99

1010
/**
@@ -60,6 +60,9 @@ class JReactNativeFeatureFlagsCxxInterop
6060
static bool disableTextLayoutManagerCacheAndroid(
6161
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
6262

63+
static bool disableViewPreallocationAndroid(
64+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
65+
6366
static bool enableAccessibilityOrder(
6467
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
6568

0 commit comments

Comments
 (0)