Skip to content

Commit

Permalink
Clean up feature flag removeNestedCallsToDispatchMountItemsOnAndroid
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal]

Clean up feature flag after we tested it's safe.

Reviewed By: javache

Differential Revision: D64332654
  • Loading branch information
rubennorte authored and facebook-github-bot committed Oct 15, 2024
1 parent 3485e9e commit da1c30d
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 197 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class MountItemDispatcher {
private final ConcurrentLinkedQueue<MountItem> mPreMountItems = new ConcurrentLinkedQueue<>();

private boolean mInDispatch = false;
private int mReDispatchCounter = 0;
private long mBatchedExecutionTime = 0L;
private long mRunStartTime = 0L;

Expand Down Expand Up @@ -119,61 +118,19 @@ public void tryDispatchMountItems() {

if (ReactNativeFeatureFlags.forceBatchingMountItemsOnAndroid()) {
mInDispatch = true;
}

try {
boolean didDispatchItems = true;
// Dispatch as many mount items as we find. Some mount items might
// trigger state updates that trigger more mount items. This will
// process them correctly.
while (didDispatchItems) {
didDispatchItems = dispatchMountItems();
}
} finally {
mInDispatch = false;
}

// We call didDispatchMountItems regardless of whether we actually dispatched anything, since
// NativeAnimatedModule relies on this for executing any animations that may have been
// scheduled
mItemDispatchListener.didDispatchMountItems();
} else {
final boolean didDispatchItems;
try {
didDispatchItems = dispatchMountItems();
} catch (Throwable e) {
mReDispatchCounter = 0;
throw e;
} finally {
// Clean up after running dispatchMountItems - even if an exception was thrown
mInDispatch = false;
}

// We call didDispatchMountItems regardless of whether we actually dispatched anything, since
// NativeAnimatedModule relies on this for executing any animations that may have been
// scheduled
mItemDispatchListener.didDispatchMountItems();

if (!ReactNativeFeatureFlags.removeNestedCallsToDispatchMountItemsOnAndroid()) {
// Decide if we want to try reentering
if (mReDispatchCounter < 10 && didDispatchItems) {
// Executing twice in a row is normal. Only log after that point.
if (mReDispatchCounter > 2) {
ReactSoftExceptionLogger.logSoftException(
TAG,
new ReactNoCrashSoftException(
"Re-dispatched "
+ mReDispatchCounter
+ " times. This indicates setState (?) is likely being called too many"
+ " times during mounting."));
}

mReDispatchCounter++;
tryDispatchMountItems();
}
}

mReDispatchCounter = 0;
try {
dispatchMountItems();
} finally {
// Clean up after running dispatchMountItems - even if an exception was thrown
mInDispatch = false;
}

// We call didDispatchMountItems regardless of whether we actually dispatched anything, since
// NativeAnimatedModule relies on this for executing any animations that may have been
// scheduled
mItemDispatchListener.didDispatchMountItems();
}

@UiThread
Expand Down Expand Up @@ -213,10 +170,8 @@ public void dispatchMountItems(Queue<MountItem> mountItems) {
*/
@UiThread
@ThreadConfined(UI)
private boolean dispatchMountItems() {
if (mReDispatchCounter == 0) {
mBatchedExecutionTime = 0;
}
private void dispatchMountItems() {
mBatchedExecutionTime = 0;

mRunStartTime = SystemClock.uptimeMillis();

Expand All @@ -225,7 +180,7 @@ private boolean dispatchMountItems() {
List<MountItem> mountItemsToDispatch = getAndResetMountItems();

if (mountItemsToDispatch == null && viewCommandMountItemsToDispatch == null) {
return false;
return;
}

mItemDispatchListener.willMountItems(mountItemsToDispatch);
Expand Down Expand Up @@ -341,8 +296,6 @@ private boolean dispatchMountItems() {
}

mItemDispatchListener.didMountItems(mountItemsToDispatch);

return true;
}

/*
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<<e568acc70be10bdd8f86caddd03cde05>>
* @generated SignedSource<<af80868112a7748983aaa6e638d0068e>>
*/

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

/**
* Removes nested calls to MountItemDispatcher.dispatchMountItems on Android, so we do less work per frame on the UI thread.
*/
@JvmStatic
public fun removeNestedCallsToDispatchMountItemsOnAndroid(): Boolean = accessor.removeNestedCallsToDispatchMountItemsOnAndroid()

/**
* Propagate layout direction to Android views.
*/
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<<a2a7b39f3f71be2a278faf2c21ede6a3>>
* @generated SignedSource<<b0a0f792ea56ce65a44de3ce90ec72ee>>
*/

/**
Expand Down Expand Up @@ -57,7 +57,6 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var initEagerTurboModulesOnNativeModulesQueueAndroidCache: Boolean? = null
private var lazyAnimationCallbacksCache: Boolean? = null
private var loadVectorDrawablesOnImagesCache: Boolean? = null
private var removeNestedCallsToDispatchMountItemsOnAndroidCache: Boolean? = null
private var setAndroidLayoutDirectionCache: Boolean? = null
private var traceTurboModulePromiseRejectionsOnAndroidCache: Boolean? = null
private var useFabricInteropCache: Boolean? = null
Expand Down Expand Up @@ -403,15 +402,6 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}

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

override fun setAndroidLayoutDirection(): Boolean {
var cached = setAndroidLayoutDirectionCache
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<<3cf8639dfd8a92a954a055c3ebdc749c>>
* @generated SignedSource<<2f1e29ca29c3679e5a87be1d0944efd9>>
*/

/**
Expand Down Expand Up @@ -102,8 +102,6 @@ public object ReactNativeFeatureFlagsCxxInterop {

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

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

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

@DoNotStrip @JvmStatic public external fun traceTurboModulePromiseRejectionsOnAndroid(): 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<<9e0db1a47596fec77c29122620b8f633>>
* @generated SignedSource<<f99453feaef7994f46278d40af544771>>
*/

/**
Expand Down Expand Up @@ -97,8 +97,6 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun loadVectorDrawablesOnImages(): Boolean = false

override fun removeNestedCallsToDispatchMountItemsOnAndroid(): Boolean = false

override fun setAndroidLayoutDirection(): Boolean = true

override fun traceTurboModulePromiseRejectionsOnAndroid(): 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<<91c4268e7e88e2e3c1f3d50d149c0d2b>>
* @generated SignedSource<<fb7bda2b8430d77435141daed4190e4a>>
*/

/**
Expand Down Expand Up @@ -61,7 +61,6 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var initEagerTurboModulesOnNativeModulesQueueAndroidCache: Boolean? = null
private var lazyAnimationCallbacksCache: Boolean? = null
private var loadVectorDrawablesOnImagesCache: Boolean? = null
private var removeNestedCallsToDispatchMountItemsOnAndroidCache: Boolean? = null
private var setAndroidLayoutDirectionCache: Boolean? = null
private var traceTurboModulePromiseRejectionsOnAndroidCache: Boolean? = null
private var useFabricInteropCache: Boolean? = null
Expand Down Expand Up @@ -444,16 +443,6 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}

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

override fun setAndroidLayoutDirection(): Boolean {
var cached = setAndroidLayoutDirectionCache
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<<193bb7803261004003d9009b44810c2c>>
* @generated SignedSource<<7abedfd47601a9edd4e2982ea1450590>>
*/

/**
Expand Down Expand Up @@ -97,8 +97,6 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun loadVectorDrawablesOnImages(): Boolean

@DoNotStrip public fun removeNestedCallsToDispatchMountItemsOnAndroid(): Boolean

@DoNotStrip public fun setAndroidLayoutDirection(): Boolean

@DoNotStrip public fun traceTurboModulePromiseRejectionsOnAndroid(): 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<<f4dba9f073137759e18fb71411232d7a>>
* @generated SignedSource<<9f5e1568b62ca76e5771fade759d42e5>>
*/

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

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

bool setAndroidLayoutDirection() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("setAndroidLayoutDirection");
Expand Down Expand Up @@ -522,11 +516,6 @@ bool JReactNativeFeatureFlagsCxxInterop::loadVectorDrawablesOnImages(
return ReactNativeFeatureFlags::loadVectorDrawablesOnImages();
}

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

bool JReactNativeFeatureFlagsCxxInterop::setAndroidLayoutDirection(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::setAndroidLayoutDirection();
Expand Down Expand Up @@ -724,9 +713,6 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"loadVectorDrawablesOnImages",
JReactNativeFeatureFlagsCxxInterop::loadVectorDrawablesOnImages),
makeNativeMethod(
"removeNestedCallsToDispatchMountItemsOnAndroid",
JReactNativeFeatureFlagsCxxInterop::removeNestedCallsToDispatchMountItemsOnAndroid),
makeNativeMethod(
"setAndroidLayoutDirection",
JReactNativeFeatureFlagsCxxInterop::setAndroidLayoutDirection),
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<<9b325f01aea83bc93db31c9a63bea3f7>>
* @generated SignedSource<<879ef38c2b34bc6cd15d6361abef1548>>
*/

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

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

static bool setAndroidLayoutDirection(
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<<14957b53f50e3ea943f0e3631475f336>>
* @generated SignedSource<<204e18de128eb47f29ef5383e592e181>>
*/

/**
Expand Down Expand Up @@ -174,10 +174,6 @@ bool ReactNativeFeatureFlags::loadVectorDrawablesOnImages() {
return getAccessor().loadVectorDrawablesOnImages();
}

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

bool ReactNativeFeatureFlags::setAndroidLayoutDirection() {
return getAccessor().setAndroidLayoutDirection();
}
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<<c5a4993e3c7093f221cce2c891d86905>>
* @generated SignedSource<<9170ab789417914123e11ecb836aaa9a>>
*/

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

/**
* Removes nested calls to MountItemDispatcher.dispatchMountItems on Android, so we do less work per frame on the UI thread.
*/
RN_EXPORT static bool removeNestedCallsToDispatchMountItemsOnAndroid();

/**
* Propagate layout direction to Android views.
*/
Expand Down
Loading

0 comments on commit da1c30d

Please sign in to comment.