Skip to content

Commit

Permalink
Clean up feature flag `allowRecursiveCommitsWithSynchronousMountOnAnd…
Browse files Browse the repository at this point in the history
…roid`

Summary:
Changelog: [Android][Fixed] Fixes some deadlocks when doing commits and state updates synchronously from the UI thread (e.g.: from reanimated).

This removes the gating for the fix to allow recursive commits with synchronous mount on Android.

See facebook#44725 (comment) and software-mansion/react-native-reanimated#6418 (comment).

Differential Revision: D66095539
  • Loading branch information
rubennorte authored and facebook-github-bot committed Nov 18, 2024
1 parent 089c87e commit 6cbe54d
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 189 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<1adfbb1f0b9791d93ea00f39fbce5520>>
* @generated SignedSource<<124e8e4892062fa63a9a70ae0c53653d>>
*/

/**
Expand Down Expand Up @@ -34,12 +34,6 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun commonTestFlag(): Boolean = accessor.commonTestFlag()

/**
* Adds support for recursively processing commits that mount synchronously (Android only).
*/
@JvmStatic
public fun allowRecursiveCommitsWithSynchronousMountOnAndroid(): Boolean = accessor.allowRecursiveCommitsWithSynchronousMountOnAndroid()

/**
* Do not wait for a main-thread dispatch to complete init to start executing work on the JS thread on Android
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<fb943b9c4c43ac8214a8f368076cbd62>>
* @generated SignedSource<<28da40176c64703dcab4bc0d1af078a8>>
*/

/**
Expand All @@ -21,7 +21,6 @@ package com.facebook.react.internal.featureflags

public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccessor {
private var commonTestFlagCache: Boolean? = null
private var allowRecursiveCommitsWithSynchronousMountOnAndroidCache: Boolean? = null
private var completeReactInstanceCreationOnBgThreadOnAndroidCache: Boolean? = null
private var disableEventLoopOnBridgelessCache: Boolean? = null
private var disableMountItemReorderingAndroidCache: Boolean? = null
Expand Down Expand Up @@ -77,15 +76,6 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}

override fun allowRecursiveCommitsWithSynchronousMountOnAndroid(): Boolean {
var cached = allowRecursiveCommitsWithSynchronousMountOnAndroidCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.allowRecursiveCommitsWithSynchronousMountOnAndroid()
allowRecursiveCommitsWithSynchronousMountOnAndroidCache = cached
}
return cached
}

override fun completeReactInstanceCreationOnBgThreadOnAndroid(): Boolean {
var cached = completeReactInstanceCreationOnBgThreadOnAndroidCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<3980c51f97745c20e0fd510f595477dc>>
* @generated SignedSource<<e53c4f66b6261f983ad1502adc31f1dc>>
*/

/**
Expand All @@ -30,8 +30,6 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun commonTestFlag(): Boolean

@DoNotStrip @JvmStatic public external fun allowRecursiveCommitsWithSynchronousMountOnAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun completeReactInstanceCreationOnBgThreadOnAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun disableEventLoopOnBridgeless(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<f4f263578308798dcf7561918f58e0cc>>
* @generated SignedSource<<3d25d7b8ee194721c39fb5eb5eda87d4>>
*/

/**
Expand All @@ -25,8 +25,6 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun commonTestFlag(): Boolean = false

override fun allowRecursiveCommitsWithSynchronousMountOnAndroid(): Boolean = false

override fun completeReactInstanceCreationOnBgThreadOnAndroid(): Boolean = true

override fun disableEventLoopOnBridgeless(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<bd3529c1455508333a45a5852c3213c6>>
* @generated SignedSource<<fb8747b040cd9c29e9ca0a7c1647ad91>>
*/

/**
Expand All @@ -25,7 +25,6 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private val accessedFeatureFlags = mutableSetOf<String>()

private var commonTestFlagCache: Boolean? = null
private var allowRecursiveCommitsWithSynchronousMountOnAndroidCache: Boolean? = null
private var completeReactInstanceCreationOnBgThreadOnAndroidCache: Boolean? = null
private var disableEventLoopOnBridgelessCache: Boolean? = null
private var disableMountItemReorderingAndroidCache: Boolean? = null
Expand Down Expand Up @@ -82,16 +81,6 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun allowRecursiveCommitsWithSynchronousMountOnAndroid(): Boolean {
var cached = allowRecursiveCommitsWithSynchronousMountOnAndroidCache
if (cached == null) {
cached = currentProvider.allowRecursiveCommitsWithSynchronousMountOnAndroid()
accessedFeatureFlags.add("allowRecursiveCommitsWithSynchronousMountOnAndroid")
allowRecursiveCommitsWithSynchronousMountOnAndroidCache = cached
}
return cached
}

override fun completeReactInstanceCreationOnBgThreadOnAndroid(): Boolean {
var cached = completeReactInstanceCreationOnBgThreadOnAndroidCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a74e9cdce26b156a74e397fd065618c2>>
* @generated SignedSource<<24bae6a173c941923c84f418a114ec2f>>
*/

/**
Expand All @@ -25,8 +25,6 @@ import com.facebook.proguard.annotations.DoNotStrip
public interface ReactNativeFeatureFlagsProvider {
@DoNotStrip public fun commonTestFlag(): Boolean

@DoNotStrip public fun allowRecursiveCommitsWithSynchronousMountOnAndroid(): Boolean

@DoNotStrip public fun completeReactInstanceCreationOnBgThreadOnAndroid(): Boolean

@DoNotStrip public fun disableEventLoopOnBridgeless(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,27 +559,24 @@ void FabricUIManagerBinding::schedulerShouldRenderTransactions(
return;
}

if (ReactNativeFeatureFlags::
allowRecursiveCommitsWithSynchronousMountOnAndroid()) {
std::vector<MountingTransaction> pendingTransactions;

{
// Retain the lock to access the pending transactions but not to execute
// the mount operations because that method can call into this method
// again.
std::unique_lock<std::mutex> lock(pendingTransactionsMutex_);
pendingTransactions_.swap(pendingTransactions);
}
std::vector<MountingTransaction> pendingTransactions;

for (auto& transaction : pendingTransactions) {
mountingManager->executeMount(transaction);
}
} else {
{
// Retain the lock to access the pending transactions but not to execute
// the mount operations because that method can call into this method
// again.
//
// This can be re-entrant when mounting manager triggers state updates
// synchronously (this can happen when committing from the UI thread).
// This is safe because we're already combining all the transactions for the
// same surface ID in a single transaction in the pending transactions list,
// so operations won't run out of order.
std::unique_lock<std::mutex> lock(pendingTransactionsMutex_);
for (auto& transaction : pendingTransactions_) {
mountingManager->executeMount(transaction);
}
pendingTransactions_.clear();
pendingTransactions_.swap(pendingTransactions);
}

for (auto& transaction : pendingTransactions) {
mountingManager->executeMount(transaction);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<9c1572172189f9f9ded86a9fdb1cb021>>
* @generated SignedSource<<17da000ed077668a52a4dacba88162b0>>
*/

/**
Expand Down Expand Up @@ -45,12 +45,6 @@ class ReactNativeFeatureFlagsProviderHolder
return method(javaProvider_);
}

bool allowRecursiveCommitsWithSynchronousMountOnAndroid() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("allowRecursiveCommitsWithSynchronousMountOnAndroid");
return method(javaProvider_);
}

bool completeReactInstanceCreationOnBgThreadOnAndroid() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("completeReactInstanceCreationOnBgThreadOnAndroid");
Expand Down Expand Up @@ -330,11 +324,6 @@ bool JReactNativeFeatureFlagsCxxInterop::commonTestFlag(
return ReactNativeFeatureFlags::commonTestFlag();
}

bool JReactNativeFeatureFlagsCxxInterop::allowRecursiveCommitsWithSynchronousMountOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::allowRecursiveCommitsWithSynchronousMountOnAndroid();
}

bool JReactNativeFeatureFlagsCxxInterop::completeReactInstanceCreationOnBgThreadOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::completeReactInstanceCreationOnBgThreadOnAndroid();
Expand Down Expand Up @@ -594,9 +583,6 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"commonTestFlag",
JReactNativeFeatureFlagsCxxInterop::commonTestFlag),
makeNativeMethod(
"allowRecursiveCommitsWithSynchronousMountOnAndroid",
JReactNativeFeatureFlagsCxxInterop::allowRecursiveCommitsWithSynchronousMountOnAndroid),
makeNativeMethod(
"completeReactInstanceCreationOnBgThreadOnAndroid",
JReactNativeFeatureFlagsCxxInterop::completeReactInstanceCreationOnBgThreadOnAndroid),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<92fcd7e8c814a6a76ec15c4cd60e00e4>>
* @generated SignedSource<<20fa39ef7b31222a0a34e131d60e6bec>>
*/

/**
Expand Down Expand Up @@ -33,9 +33,6 @@ class JReactNativeFeatureFlagsCxxInterop
static bool commonTestFlag(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool allowRecursiveCommitsWithSynchronousMountOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool completeReactInstanceCreationOnBgThreadOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<93b93588adcd6b45ec748dff7ee18f07>>
* @generated SignedSource<<cfa6f544c0bcb190836329d8f597efc6>>
*/

/**
Expand All @@ -30,10 +30,6 @@ bool ReactNativeFeatureFlags::commonTestFlag() {
return getAccessor().commonTestFlag();
}

bool ReactNativeFeatureFlags::allowRecursiveCommitsWithSynchronousMountOnAndroid() {
return getAccessor().allowRecursiveCommitsWithSynchronousMountOnAndroid();
}

bool ReactNativeFeatureFlags::completeReactInstanceCreationOnBgThreadOnAndroid() {
return getAccessor().completeReactInstanceCreationOnBgThreadOnAndroid();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<b24144040cb5bd51f9910b81675ba5b2>>
* @generated SignedSource<<0c0217362f582ac635d5f46347e65252>>
*/

/**
Expand Down Expand Up @@ -44,11 +44,6 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool commonTestFlag();

/**
* Adds support for recursively processing commits that mount synchronously (Android only).
*/
RN_EXPORT static bool allowRecursiveCommitsWithSynchronousMountOnAndroid();

/**
* Do not wait for a main-thread dispatch to complete init to start executing work on the JS thread on Android
*/
Expand Down
Loading

0 comments on commit 6cbe54d

Please sign in to comment.