Skip to content

Commit 4655f20

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
add feature flag to disable Choreographer callbacks in Paper infra
Summary: changelog: [internal] For constrained environments, we want to lower cpu usage of RN when the app is idle. `UIViewOperationQueue` and `EventDispatcherImpl` are not used in Fabric and therefore they do not need to run on each frame. Reviewed By: javache Differential Revision: D50741161 fbshipit-source-id: aa605893f1c8a4ac97a49bb7a6de2e2637a0832e
1 parent e2eb26c commit 4655f20

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,12 @@ public class ReactFeatureFlags {
174174
* in JS will be rejected (The JS error will include native stack)
175175
*/
176176
public static boolean rejectTurboModulePromiseOnNativeError = true;
177+
178+
/*
179+
* When the app is completely migrated to Fabric, set this flag to true to
180+
* disable parts of Paper infrastructre that are not needed anymore but consume
181+
* memory and CPU. Specifically, UIViewOperationQueue and EventDispatcherImpl will no
182+
* longer work as they won't subscribe to ReactChoregrapher for updates.
183+
*/
184+
public static boolean enableFabricRendererExclusively = false;
177185
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIViewOperationQueue.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.facebook.react.bridge.SoftAssertions;
2626
import com.facebook.react.bridge.UiThreadUtil;
2727
import com.facebook.react.common.ReactConstants;
28+
import com.facebook.react.config.ReactFeatureFlags;
2829
import com.facebook.react.modules.core.ReactChoreographer;
2930
import com.facebook.react.uimanager.debug.NotThreadSafeViewHierarchyUpdateDebugListener;
3031
import com.facebook.systrace.Systrace;
@@ -962,8 +963,10 @@ public void runGuarded() {
962963

963964
/* package */ void resumeFrameCallback() {
964965
mIsDispatchUIFrameCallbackEnqueued = true;
965-
ReactChoreographer.getInstance()
966-
.postFrameCallback(ReactChoreographer.CallbackType.DISPATCH_UI, mDispatchUIFrameCallback);
966+
if (!ReactFeatureFlags.enableFabricRendererExclusively) {
967+
ReactChoreographer.getInstance()
968+
.postFrameCallback(ReactChoreographer.CallbackType.DISPATCH_UI, mDispatchUIFrameCallback);
969+
}
967970
}
968971

969972
/* package */ void pauseFrameCallback() {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.facebook.react.bridge.ReactApplicationContext;
1515
import com.facebook.react.bridge.UiThreadUtil;
1616
import com.facebook.react.common.MapBuilder;
17+
import com.facebook.react.config.ReactFeatureFlags;
1718
import com.facebook.react.modules.core.ReactChoreographer;
1819
import com.facebook.react.uimanager.common.UIManagerType;
1920
import com.facebook.systrace.Systrace;
@@ -315,8 +316,11 @@ public void maybePost() {
315316
}
316317

317318
private void post() {
318-
ReactChoreographer.getInstance()
319-
.postFrameCallback(ReactChoreographer.CallbackType.TIMERS_EVENTS, mCurrentFrameCallback);
319+
if (!ReactFeatureFlags.enableFabricRendererExclusively) {
320+
ReactChoreographer.getInstance()
321+
.postFrameCallback(
322+
ReactChoreographer.CallbackType.TIMERS_EVENTS, mCurrentFrameCallback);
323+
}
320324
}
321325

322326
public void maybePostFromNonUI() {

0 commit comments

Comments
 (0)