Skip to content

Commit dca6f6d

Browse files
Nick Lefevermeta-codesync[bot]
authored andcommitted
Add feature flag to disable view preallocation only for images (#54443)
Summary: Pull Request resolved: #54443 Add a feature flag to disable view preallocation only for images on Android Changelog: [Internal] Reviewed By: javache Differential Revision: D86488126 fbshipit-source-id: fa98b7d2cdd41a05c413bd668cc7b1e7c6c6a147
1 parent d2bbd5a commit dca6f6d

21 files changed

+222
-97
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<<aa1ec8f536bf908fc0f0eebd0a57b588>>
7+
* @generated SignedSource<<01feab16132bc07b79b359178e322327>>
88
*/
99

1010
/**
@@ -66,6 +66,12 @@ public object ReactNativeFeatureFlags {
6666
@JvmStatic
6767
public fun disableFabricCommitInCXXAnimated(): Boolean = accessor.disableFabricCommitInCXXAnimated()
6868

69+
/**
70+
* Force disable view preallocation for images triggered from createNode off the main thread on Android
71+
*/
72+
@JvmStatic
73+
public fun disableImageViewPreallocationAndroid(): Boolean = accessor.disableImageViewPreallocationAndroid()
74+
6975
/**
7076
* Prevent FabricMountingManager from reordering mountItems, which may lead to invalid state on the UI thread
7177
*/

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

1010
/**
@@ -26,6 +26,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
2626
private var cxxNativeAnimatedRemoveJsSyncCache: Boolean? = null
2727
private var disableEarlyViewCommandExecutionCache: Boolean? = null
2828
private var disableFabricCommitInCXXAnimatedCache: Boolean? = null
29+
private var disableImageViewPreallocationAndroidCache: Boolean? = null
2930
private var disableMountItemReorderingAndroidCache: Boolean? = null
3031
private var disableOldAndroidAttachmentMetricsWorkaroundsCache: Boolean? = null
3132
private var disableSubviewClippingAndroidCache: Boolean? = null
@@ -158,6 +159,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
158159
return cached
159160
}
160161

162+
override fun disableImageViewPreallocationAndroid(): Boolean {
163+
var cached = disableImageViewPreallocationAndroidCache
164+
if (cached == null) {
165+
cached = ReactNativeFeatureFlagsCxxInterop.disableImageViewPreallocationAndroid()
166+
disableImageViewPreallocationAndroidCache = cached
167+
}
168+
return cached
169+
}
170+
161171
override fun disableMountItemReorderingAndroid(): Boolean {
162172
var cached = disableMountItemReorderingAndroidCache
163173
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<<00737feba90fb1ffbd9c4e7c2b83a239>>
7+
* @generated SignedSource<<bffd645aa55b941acff92ca4efe6192a>>
88
*/
99

1010
/**
@@ -40,6 +40,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
4040

4141
@DoNotStrip @JvmStatic public external fun disableFabricCommitInCXXAnimated(): Boolean
4242

43+
@DoNotStrip @JvmStatic public external fun disableImageViewPreallocationAndroid(): Boolean
44+
4345
@DoNotStrip @JvmStatic public external fun disableMountItemReorderingAndroid(): Boolean
4446

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

1010
/**
@@ -35,6 +35,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
3535

3636
override fun disableFabricCommitInCXXAnimated(): Boolean = false
3737

38+
override fun disableImageViewPreallocationAndroid(): Boolean = false
39+
3840
override fun disableMountItemReorderingAndroid(): Boolean = false
3941

4042
override fun disableOldAndroidAttachmentMetricsWorkarounds(): Boolean = true

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<<53a55696d6897c5bf0ce8b5389d4c7f9>>
7+
* @generated SignedSource<<e8531e8c374d0ea1e604a2f3d5000078>>
88
*/
99

1010
/**
@@ -30,6 +30,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
3030
private var cxxNativeAnimatedRemoveJsSyncCache: Boolean? = null
3131
private var disableEarlyViewCommandExecutionCache: Boolean? = null
3232
private var disableFabricCommitInCXXAnimatedCache: Boolean? = null
33+
private var disableImageViewPreallocationAndroidCache: Boolean? = null
3334
private var disableMountItemReorderingAndroidCache: Boolean? = null
3435
private var disableOldAndroidAttachmentMetricsWorkaroundsCache: Boolean? = null
3536
private var disableSubviewClippingAndroidCache: Boolean? = null
@@ -168,6 +169,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
168169
return cached
169170
}
170171

172+
override fun disableImageViewPreallocationAndroid(): Boolean {
173+
var cached = disableImageViewPreallocationAndroidCache
174+
if (cached == null) {
175+
cached = currentProvider.disableImageViewPreallocationAndroid()
176+
accessedFeatureFlags.add("disableImageViewPreallocationAndroid")
177+
disableImageViewPreallocationAndroidCache = cached
178+
}
179+
return cached
180+
}
181+
171182
override fun disableMountItemReorderingAndroid(): Boolean {
172183
var cached = disableMountItemReorderingAndroidCache
173184
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<<f8c3a4173b151b4560aa2f98e3969ff1>>
7+
* @generated SignedSource<<2325f5410537941e25998ca8c59bf51d>>
88
*/
99

1010
/**
@@ -35,6 +35,8 @@ public interface ReactNativeFeatureFlagsProvider {
3535

3636
@DoNotStrip public fun disableFabricCommitInCXXAnimated(): Boolean
3737

38+
@DoNotStrip public fun disableImageViewPreallocationAndroid(): Boolean
39+
3840
@DoNotStrip public fun disableMountItemReorderingAndroid(): Boolean
3941

4042
@DoNotStrip public fun disableOldAndroidAttachmentMetricsWorkarounds(): Boolean

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <react/renderer/scheduler/SchedulerToolbox.h>
3030
#include <react/renderer/uimanager/primitives.h>
3131
#include <react/utils/ContextContainer.h>
32+
#include <string_view>
3233

3334
namespace facebook::react {
3435

@@ -672,10 +673,17 @@ void FabricUIManagerBinding::schedulerShouldRenderTransactions(
672673

673674
void FabricUIManagerBinding::schedulerDidRequestPreliminaryViewAllocation(
674675
const ShadowNode& shadowNode) {
676+
using namespace std::literals::string_view_literals;
677+
675678
if (ReactNativeFeatureFlags::disableViewPreallocationAndroid()) {
676679
return;
677680
}
678681

682+
if (ReactNativeFeatureFlags::disableImageViewPreallocationAndroid() &&
683+
std::string_view(shadowNode.getComponentName()) == "Image"sv) {
684+
return;
685+
}
686+
679687
auto mountingManager = getMountingManager("preallocateView");
680688
if (!mountingManager) {
681689
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<<f5be088886181124b1b9bb1b59222689>>
7+
* @generated SignedSource<<95ebd4929bf0f98aa059ad4b8139f7b3>>
88
*/
99

1010
/**
@@ -75,6 +75,12 @@ class ReactNativeFeatureFlagsJavaProvider
7575
return method(javaProvider_);
7676
}
7777

78+
bool disableImageViewPreallocationAndroid() override {
79+
static const auto method =
80+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("disableImageViewPreallocationAndroid");
81+
return method(javaProvider_);
82+
}
83+
7884
bool disableMountItemReorderingAndroid() override {
7985
static const auto method =
8086
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("disableMountItemReorderingAndroid");
@@ -571,6 +577,11 @@ bool JReactNativeFeatureFlagsCxxInterop::disableFabricCommitInCXXAnimated(
571577
return ReactNativeFeatureFlags::disableFabricCommitInCXXAnimated();
572578
}
573579

580+
bool JReactNativeFeatureFlagsCxxInterop::disableImageViewPreallocationAndroid(
581+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
582+
return ReactNativeFeatureFlags::disableImageViewPreallocationAndroid();
583+
}
584+
574585
bool JReactNativeFeatureFlagsCxxInterop::disableMountItemReorderingAndroid(
575586
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
576587
return ReactNativeFeatureFlags::disableMountItemReorderingAndroid();
@@ -1005,6 +1016,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
10051016
makeNativeMethod(
10061017
"disableFabricCommitInCXXAnimated",
10071018
JReactNativeFeatureFlagsCxxInterop::disableFabricCommitInCXXAnimated),
1019+
makeNativeMethod(
1020+
"disableImageViewPreallocationAndroid",
1021+
JReactNativeFeatureFlagsCxxInterop::disableImageViewPreallocationAndroid),
10081022
makeNativeMethod(
10091023
"disableMountItemReorderingAndroid",
10101024
JReactNativeFeatureFlagsCxxInterop::disableMountItemReorderingAndroid),

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

1010
/**
@@ -48,6 +48,9 @@ class JReactNativeFeatureFlagsCxxInterop
4848
static bool disableFabricCommitInCXXAnimated(
4949
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
5050

51+
static bool disableImageViewPreallocationAndroid(
52+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
53+
5154
static bool disableMountItemReorderingAndroid(
5255
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
5356

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<<1470d79395e4b5fcda336521a70d6509>>
7+
* @generated SignedSource<<1a4d03b0d58e389dc9e9af0adf7afa9f>>
88
*/
99

1010
/**
@@ -50,6 +50,10 @@ bool ReactNativeFeatureFlags::disableFabricCommitInCXXAnimated() {
5050
return getAccessor().disableFabricCommitInCXXAnimated();
5151
}
5252

53+
bool ReactNativeFeatureFlags::disableImageViewPreallocationAndroid() {
54+
return getAccessor().disableImageViewPreallocationAndroid();
55+
}
56+
5357
bool ReactNativeFeatureFlags::disableMountItemReorderingAndroid() {
5458
return getAccessor().disableMountItemReorderingAndroid();
5559
}

0 commit comments

Comments
 (0)