Skip to content

Commit 2de4984

Browse files
rubennortefacebook-github-bot
authored andcommitted
Implement solution for ShadowTree commmit exhaustion using recursive locks (behind a flag) (#52795)
Summary: Pull Request resolved: #52795 Changelog: [internal] This is another attempt to fix #51870, inspired by #52314 but gated behind a feature flag until we've tested it carefully. Reviewed By: sammy-SC Differential Revision: D78817100 fbshipit-source-id: 45e6cae019b212528f2b2e74b9f52fe43d07f537
1 parent c6c7c37 commit 2de4984

24 files changed

Lines changed: 223 additions & 51 deletions

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<<a5908495c093849007082e6297647f8a>>
7+
* @generated SignedSource<<92170b32c13dc405a81b4a5cf5677afb>>
88
*/
99

1010
/**
@@ -312,6 +312,12 @@ public object ReactNativeFeatureFlags {
312312
@JvmStatic
313313
public fun preparedTextCacheSize(): Double = accessor.preparedTextCacheSize()
314314

315+
/**
316+
* 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.
317+
*/
318+
@JvmStatic
319+
public fun preventShadowTreeCommitExhaustion(): Boolean = accessor.preventShadowTreeCommitExhaustion()
320+
315321
/**
316322
* Releases the cached image data when it is consumed by the observers.
317323
*/

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<<d4f92fba9ba8b4d457587446ce069d32>>
7+
* @generated SignedSource<<34c0a7def872e270cd542785d9bfde40>>
88
*/
99

1010
/**
@@ -67,6 +67,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
6767
private var fuseboxNetworkInspectionEnabledCache: Boolean? = null
6868
private var hideOffscreenVirtualViewsOnIOSCache: Boolean? = null
6969
private var preparedTextCacheSizeCache: Double? = null
70+
private var preventShadowTreeCommitExhaustionCache: Boolean? = null
7071
private var releaseImageDataWhenConsumedCache: Boolean? = null
7172
private var shouldPressibilityUseW3CPointerEventsForHoverCache: Boolean? = null
7273
private var skipActivityIdentityAssertionOnHostPauseCache: Boolean? = null
@@ -507,6 +508,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
507508
return cached
508509
}
509510

511+
override fun preventShadowTreeCommitExhaustion(): Boolean {
512+
var cached = preventShadowTreeCommitExhaustionCache
513+
if (cached == null) {
514+
cached = ReactNativeFeatureFlagsCxxInterop.preventShadowTreeCommitExhaustion()
515+
preventShadowTreeCommitExhaustionCache = cached
516+
}
517+
return cached
518+
}
519+
510520
override fun releaseImageDataWhenConsumed(): Boolean {
511521
var cached = releaseImageDataWhenConsumedCache
512522
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<<568d3a6628dd6cc9b32a77c590210730>>
7+
* @generated SignedSource<<3c9a5f37b4d141ffcf9a2ec152f70563>>
88
*/
99

1010
/**
@@ -122,6 +122,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
122122

123123
@DoNotStrip @JvmStatic public external fun preparedTextCacheSize(): Double
124124

125+
@DoNotStrip @JvmStatic public external fun preventShadowTreeCommitExhaustion(): Boolean
126+
125127
@DoNotStrip @JvmStatic public external fun releaseImageDataWhenConsumed(): Boolean
126128

127129
@DoNotStrip @JvmStatic public external fun shouldPressibilityUseW3CPointerEventsForHover(): 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<<276706dd4eef0370e61fc36e3420f0aa>>
7+
* @generated SignedSource<<728ae563ec31340ccc8c4c593d566c64>>
88
*/
99

1010
/**
@@ -117,6 +117,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
117117

118118
override fun preparedTextCacheSize(): Double = 200.0
119119

120+
override fun preventShadowTreeCommitExhaustion(): Boolean = false
121+
120122
override fun releaseImageDataWhenConsumed(): Boolean = false
121123

122124
override fun shouldPressibilityUseW3CPointerEventsForHover(): 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<<c387f3ce74df2fc0120f5abd0dcb2f9b>>
7+
* @generated SignedSource<<9a5b0bdc0bd9ab0889e548b25cfe5371>>
88
*/
99

1010
/**
@@ -71,6 +71,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
7171
private var fuseboxNetworkInspectionEnabledCache: Boolean? = null
7272
private var hideOffscreenVirtualViewsOnIOSCache: Boolean? = null
7373
private var preparedTextCacheSizeCache: Double? = null
74+
private var preventShadowTreeCommitExhaustionCache: Boolean? = null
7475
private var releaseImageDataWhenConsumedCache: Boolean? = null
7576
private var shouldPressibilityUseW3CPointerEventsForHoverCache: Boolean? = null
7677
private var skipActivityIdentityAssertionOnHostPauseCache: Boolean? = null
@@ -558,6 +559,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
558559
return cached
559560
}
560561

562+
override fun preventShadowTreeCommitExhaustion(): Boolean {
563+
var cached = preventShadowTreeCommitExhaustionCache
564+
if (cached == null) {
565+
cached = currentProvider.preventShadowTreeCommitExhaustion()
566+
accessedFeatureFlags.add("preventShadowTreeCommitExhaustion")
567+
preventShadowTreeCommitExhaustionCache = cached
568+
}
569+
return cached
570+
}
571+
561572
override fun releaseImageDataWhenConsumed(): Boolean {
562573
var cached = releaseImageDataWhenConsumedCache
563574
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsOverrides_RNOSS_Experimental_Android.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<<636ec2163060c2ef6fdbc5e27ef41716>>
7+
* @generated SignedSource<<0bafb0a2fb79c4220d21f1736894af14>>
88
*/
99

1010
/**
@@ -23,6 +23,8 @@ public open class ReactNativeFeatureFlagsOverrides_RNOSS_Experimental_Android :
2323
// We could use JNI to get the defaults from C++,
2424
// but that is more expensive than just duplicating the defaults here.
2525

26+
override fun preventShadowTreeCommitExhaustion(): Boolean = true
27+
2628
override fun useNativeEqualsInNativeReadableArrayAndroid(): Boolean = true
2729

2830
override fun useNativeTransformHelperAndroid(): Boolean = true

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<<68ec2f18b3554bcd6e3e10c530d8cca0>>
7+
* @generated SignedSource<<ee4525af457a5ad08f506cf8447a4156>>
88
*/
99

1010
/**
@@ -117,6 +117,8 @@ public interface ReactNativeFeatureFlagsProvider {
117117

118118
@DoNotStrip public fun preparedTextCacheSize(): Double
119119

120+
@DoNotStrip public fun preventShadowTreeCommitExhaustion(): Boolean
121+
120122
@DoNotStrip public fun releaseImageDataWhenConsumed(): Boolean
121123

122124
@DoNotStrip public fun shouldPressibilityUseW3CPointerEventsForHover(): 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<<c00ad0b31911831b23dd4c9ebab1c494>>
7+
* @generated SignedSource<<fa975c22ecec781f4621cad8b90ea290>>
88
*/
99

1010
/**
@@ -321,6 +321,12 @@ class ReactNativeFeatureFlagsJavaProvider
321321
return method(javaProvider_);
322322
}
323323

324+
bool preventShadowTreeCommitExhaustion() override {
325+
static const auto method =
326+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("preventShadowTreeCommitExhaustion");
327+
return method(javaProvider_);
328+
}
329+
324330
bool releaseImageDataWhenConsumed() override {
325331
static const auto method =
326332
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("releaseImageDataWhenConsumed");
@@ -656,6 +662,11 @@ double JReactNativeFeatureFlagsCxxInterop::preparedTextCacheSize(
656662
return ReactNativeFeatureFlags::preparedTextCacheSize();
657663
}
658664

665+
bool JReactNativeFeatureFlagsCxxInterop::preventShadowTreeCommitExhaustion(
666+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
667+
return ReactNativeFeatureFlags::preventShadowTreeCommitExhaustion();
668+
}
669+
659670
bool JReactNativeFeatureFlagsCxxInterop::releaseImageDataWhenConsumed(
660671
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
661672
return ReactNativeFeatureFlags::releaseImageDataWhenConsumed();
@@ -908,6 +919,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
908919
makeNativeMethod(
909920
"preparedTextCacheSize",
910921
JReactNativeFeatureFlagsCxxInterop::preparedTextCacheSize),
922+
makeNativeMethod(
923+
"preventShadowTreeCommitExhaustion",
924+
JReactNativeFeatureFlagsCxxInterop::preventShadowTreeCommitExhaustion),
911925
makeNativeMethod(
912926
"releaseImageDataWhenConsumed",
913927
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<<9ad2d870c21a193730e937d566aae5dc>>
7+
* @generated SignedSource<<3e83546899ed1194fe03f143865ba97a>>
88
*/
99

1010
/**
@@ -171,6 +171,9 @@ class JReactNativeFeatureFlagsCxxInterop
171171
static double preparedTextCacheSize(
172172
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
173173

174+
static bool preventShadowTreeCommitExhaustion(
175+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
176+
174177
static bool releaseImageDataWhenConsumed(
175178
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
176179

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<<4ee4c8163356e7777ab080a9364a5492>>
7+
* @generated SignedSource<<21d92927b8b282b29ed9ff5795c60f8a>>
88
*/
99

1010
/**
@@ -214,6 +214,10 @@ double ReactNativeFeatureFlags::preparedTextCacheSize() {
214214
return getAccessor().preparedTextCacheSize();
215215
}
216216

217+
bool ReactNativeFeatureFlags::preventShadowTreeCommitExhaustion() {
218+
return getAccessor().preventShadowTreeCommitExhaustion();
219+
}
220+
217221
bool ReactNativeFeatureFlags::releaseImageDataWhenConsumed() {
218222
return getAccessor().releaseImageDataWhenConsumed();
219223
}

0 commit comments

Comments
 (0)