Skip to content

Commit 21cd09d

Browse files
rubennortefacebook-github-bot
authored andcommitted
Implement mechanism to prevent ShadowTree commit exhaustion (#52645)
Summary: Pull Request resolved: #52645 Changelog: [internal] This add a new feature flag to test a fix for #51870 Reviewed By: cortinico, sammy-SC Differential Revision: D78418504 fbshipit-source-id: 2792026b6936393d196fd1e3162f8b2c61a38ed6
1 parent d00de31 commit 21cd09d

21 files changed

+178
-43
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<<3212fc0e52bffab8e56359d207a22357>>
7+
* @generated SignedSource<<a90efac589511beb130c499e51150de8>>
88
*/
99

1010
/**
@@ -306,6 +306,12 @@ public object ReactNativeFeatureFlags {
306306
@JvmStatic
307307
public fun preparedTextCacheSize(): Double = accessor.preparedTextCacheSize()
308308

309+
/**
310+
* Enables a new mechanism in ShadowTree to prevent problems caused by multiple threads trying to commit concurrently. If a thread tries to commit a few times unsuccessfully, it will acquire a lock and try again.
311+
*/
312+
@JvmStatic
313+
public fun preventShadowTreeCommitExhaustionWithLocking(): Boolean = accessor.preventShadowTreeCommitExhaustionWithLocking()
314+
309315
/**
310316
* Releases the cached image data when it is consumed by the observers.
311317
*/

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<<889f905c29a3558eb172782cccd521c4>>
7+
* @generated SignedSource<<b32f66fb09971e786dd1380bbf417720>>
88
*/
99

1010
/**
@@ -66,6 +66,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
6666
private var fuseboxNetworkInspectionEnabledCache: Boolean? = null
6767
private var hideOffscreenVirtualViewsOnIOSCache: Boolean? = null
6868
private var preparedTextCacheSizeCache: Double? = null
69+
private var preventShadowTreeCommitExhaustionWithLockingCache: Boolean? = null
6970
private var releaseImageDataWhenConsumedCache: Boolean? = null
7071
private var skipActivityIdentityAssertionOnHostPauseCache: Boolean? = null
7172
private var traceTurboModulePromiseRejectionsOnAndroidCache: Boolean? = null
@@ -496,6 +497,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
496497
return cached
497498
}
498499

500+
override fun preventShadowTreeCommitExhaustionWithLocking(): Boolean {
501+
var cached = preventShadowTreeCommitExhaustionWithLockingCache
502+
if (cached == null) {
503+
cached = ReactNativeFeatureFlagsCxxInterop.preventShadowTreeCommitExhaustionWithLocking()
504+
preventShadowTreeCommitExhaustionWithLockingCache = cached
505+
}
506+
return cached
507+
}
508+
499509
override fun releaseImageDataWhenConsumed(): Boolean {
500510
var cached = releaseImageDataWhenConsumedCache
501511
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<<69a932d66b50ac8c059b0dab68313616>>
7+
* @generated SignedSource<<d1da48f826bc6a1793d1630cb89cb5c1>>
88
*/
99

1010
/**
@@ -120,6 +120,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
120120

121121
@DoNotStrip @JvmStatic public external fun preparedTextCacheSize(): Double
122122

123+
@DoNotStrip @JvmStatic public external fun preventShadowTreeCommitExhaustionWithLocking(): Boolean
124+
123125
@DoNotStrip @JvmStatic public external fun releaseImageDataWhenConsumed(): Boolean
124126

125127
@DoNotStrip @JvmStatic public external fun skipActivityIdentityAssertionOnHostPause(): 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<<90dadccf847e0f5fc24d3b1090bba82f>>
7+
* @generated SignedSource<<99019349a8f3642c42e6dac5f1476e7f>>
88
*/
99

1010
/**
@@ -115,6 +115,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
115115

116116
override fun preparedTextCacheSize(): Double = 200.0
117117

118+
override fun preventShadowTreeCommitExhaustionWithLocking(): Boolean = false
119+
118120
override fun releaseImageDataWhenConsumed(): Boolean = false
119121

120122
override fun skipActivityIdentityAssertionOnHostPause(): 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<<8663dc63e60ec71e7bf1d5645c39c77f>>
7+
* @generated SignedSource<<23605f090bfbebe911caa9d3d834d3e8>>
88
*/
99

1010
/**
@@ -70,6 +70,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
7070
private var fuseboxNetworkInspectionEnabledCache: Boolean? = null
7171
private var hideOffscreenVirtualViewsOnIOSCache: Boolean? = null
7272
private var preparedTextCacheSizeCache: Double? = null
73+
private var preventShadowTreeCommitExhaustionWithLockingCache: Boolean? = null
7374
private var releaseImageDataWhenConsumedCache: Boolean? = null
7475
private var skipActivityIdentityAssertionOnHostPauseCache: Boolean? = null
7576
private var traceTurboModulePromiseRejectionsOnAndroidCache: Boolean? = null
@@ -546,6 +547,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
546547
return cached
547548
}
548549

550+
override fun preventShadowTreeCommitExhaustionWithLocking(): Boolean {
551+
var cached = preventShadowTreeCommitExhaustionWithLockingCache
552+
if (cached == null) {
553+
cached = currentProvider.preventShadowTreeCommitExhaustionWithLocking()
554+
accessedFeatureFlags.add("preventShadowTreeCommitExhaustionWithLocking")
555+
preventShadowTreeCommitExhaustionWithLockingCache = cached
556+
}
557+
return cached
558+
}
559+
549560
override fun releaseImageDataWhenConsumed(): Boolean {
550561
var cached = releaseImageDataWhenConsumedCache
551562
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<<07caa03ff4d6e1e624a9a71d5aeceebe>>
7+
* @generated SignedSource<<780793412b76f101be1569d7a866c435>>
88
*/
99

1010
/**
@@ -115,6 +115,8 @@ public interface ReactNativeFeatureFlagsProvider {
115115

116116
@DoNotStrip public fun preparedTextCacheSize(): Double
117117

118+
@DoNotStrip public fun preventShadowTreeCommitExhaustionWithLocking(): Boolean
119+
118120
@DoNotStrip public fun releaseImageDataWhenConsumed(): Boolean
119121

120122
@DoNotStrip public fun skipActivityIdentityAssertionOnHostPause(): 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<<8121b9fc632bb1db16a1554ea5dd0b87>>
7+
* @generated SignedSource<<f310a5dc27fd655eab4445cb25d4c85c>>
88
*/
99

1010
/**
@@ -315,6 +315,12 @@ class ReactNativeFeatureFlagsJavaProvider
315315
return method(javaProvider_);
316316
}
317317

318+
bool preventShadowTreeCommitExhaustionWithLocking() override {
319+
static const auto method =
320+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("preventShadowTreeCommitExhaustionWithLocking");
321+
return method(javaProvider_);
322+
}
323+
318324
bool releaseImageDataWhenConsumed() override {
319325
static const auto method =
320326
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("releaseImageDataWhenConsumed");
@@ -639,6 +645,11 @@ double JReactNativeFeatureFlagsCxxInterop::preparedTextCacheSize(
639645
return ReactNativeFeatureFlags::preparedTextCacheSize();
640646
}
641647

648+
bool JReactNativeFeatureFlagsCxxInterop::preventShadowTreeCommitExhaustionWithLocking(
649+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
650+
return ReactNativeFeatureFlags::preventShadowTreeCommitExhaustionWithLocking();
651+
}
652+
642653
bool JReactNativeFeatureFlagsCxxInterop::releaseImageDataWhenConsumed(
643654
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
644655
return ReactNativeFeatureFlags::releaseImageDataWhenConsumed();
@@ -883,6 +894,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
883894
makeNativeMethod(
884895
"preparedTextCacheSize",
885896
JReactNativeFeatureFlagsCxxInterop::preparedTextCacheSize),
897+
makeNativeMethod(
898+
"preventShadowTreeCommitExhaustionWithLocking",
899+
JReactNativeFeatureFlagsCxxInterop::preventShadowTreeCommitExhaustionWithLocking),
886900
makeNativeMethod(
887901
"releaseImageDataWhenConsumed",
888902
JReactNativeFeatureFlagsCxxInterop::releaseImageDataWhenConsumed),

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<<1cfdc8abd4434d8b40d685b9beb79e3c>>
7+
* @generated SignedSource<<8c1da07c0b7d2053f7fdaac4326c3ac1>>
88
*/
99

1010
/**
@@ -168,6 +168,9 @@ class JReactNativeFeatureFlagsCxxInterop
168168
static double preparedTextCacheSize(
169169
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
170170

171+
static bool preventShadowTreeCommitExhaustionWithLocking(
172+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
173+
171174
static bool releaseImageDataWhenConsumed(
172175
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
173176

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<<3e49ef5b83d57ba597a2675693046ec2>>
7+
* @generated SignedSource<<355265aa8f13e3f307d6e30db6b80d41>>
88
*/
99

1010
/**
@@ -210,6 +210,10 @@ double ReactNativeFeatureFlags::preparedTextCacheSize() {
210210
return getAccessor().preparedTextCacheSize();
211211
}
212212

213+
bool ReactNativeFeatureFlags::preventShadowTreeCommitExhaustionWithLocking() {
214+
return getAccessor().preventShadowTreeCommitExhaustionWithLocking();
215+
}
216+
213217
bool ReactNativeFeatureFlags::releaseImageDataWhenConsumed() {
214218
return getAccessor().releaseImageDataWhenConsumed();
215219
}

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<<191db129f17bcf82d2d133484124867b>>
7+
* @generated SignedSource<<c584290ce61ee78bdf843c19dd40c40d>>
88
*/
99

1010
/**
@@ -269,6 +269,11 @@ class ReactNativeFeatureFlags {
269269
*/
270270
RN_EXPORT static double preparedTextCacheSize();
271271

272+
/**
273+
* Enables a new mechanism in ShadowTree to prevent problems caused by multiple threads trying to commit concurrently. If a thread tries to commit a few times unsuccessfully, it will acquire a lock and try again.
274+
*/
275+
RN_EXPORT static bool preventShadowTreeCommitExhaustionWithLocking();
276+
272277
/**
273278
* Releases the cached image data when it is consumed by the observers.
274279
*/

0 commit comments

Comments
 (0)