Skip to content

Commit

Permalink
Ship IntBufferBatchMountItem experiment
Browse files Browse the repository at this point in the history
Summary:
This experiment has been successfully running for several weeks and show small but statsig perf improvements. Delete the old code and ship this 100% in code to simplify Fabric code.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D25775668

fbshipit-source-id: d2b41dfe691775e52b1e89c2fb6790a6500e560e
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Jan 5, 2021
1 parent a2164f4 commit 0db56f1
Show file tree
Hide file tree
Showing 13 changed files with 6 additions and 1,193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,13 @@
import com.facebook.react.fabric.events.FabricEventEmitter;
import com.facebook.react.fabric.mounting.LayoutMetricsConversions;
import com.facebook.react.fabric.mounting.MountingManager;
import com.facebook.react.fabric.mounting.mountitems.BatchMountItem;
import com.facebook.react.fabric.mounting.mountitems.CreateMountItem;
import com.facebook.react.fabric.mounting.mountitems.DispatchCommandMountItem;
import com.facebook.react.fabric.mounting.mountitems.DispatchIntCommandMountItem;
import com.facebook.react.fabric.mounting.mountitems.DispatchStringCommandMountItem;
import com.facebook.react.fabric.mounting.mountitems.InsertMountItem;
import com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem;
import com.facebook.react.fabric.mounting.mountitems.MountItem;
import com.facebook.react.fabric.mounting.mountitems.PreAllocateViewMountItem;
import com.facebook.react.fabric.mounting.mountitems.RemoveDeleteMultiMountItem;
import com.facebook.react.fabric.mounting.mountitems.SendAccessibilityEvent;
import com.facebook.react.fabric.mounting.mountitems.UpdateEventEmitterMountItem;
import com.facebook.react.fabric.mounting.mountitems.UpdateLayoutMountItem;
import com.facebook.react.fabric.mounting.mountitems.UpdatePaddingMountItem;
import com.facebook.react.fabric.mounting.mountitems.UpdatePropsMountItem;
import com.facebook.react.fabric.mounting.mountitems.UpdateStateMountItem;
import com.facebook.react.uimanager.StateWrapper;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.events.BatchEventDispatchedListener;
Expand Down Expand Up @@ -107,21 +99,12 @@ private static void loadClasses() {
EventBeatManager.class.getClass();
EventEmitterWrapper.class.getClass();
FabricEventEmitter.class.getClass();
BatchMountItem.class.getClass();
CreateMountItem.class.getClass();
DispatchCommandMountItem.class.getClass();
DispatchIntCommandMountItem.class.getClass();
DispatchStringCommandMountItem.class.getClass();
InsertMountItem.class.getClass();
MountItem.class.getClass();
PreAllocateViewMountItem.class.getClass();
RemoveDeleteMultiMountItem.class.getClass();
SendAccessibilityEvent.class.getClass();
UpdateEventEmitterMountItem.class.getClass();
UpdateLayoutMountItem.class.getClass();
UpdatePaddingMountItem.class.getClass();
UpdatePropsMountItem.class.getClass();
UpdateStateMountItem.class.getClass();
LayoutMetricsConversions.class.getClass();
MountingManager.class.getClass();
Binding.class.getClass();
Expand All @@ -134,5 +117,6 @@ private static void loadClasses() {
StateWrapperImpl.class.getClass();
BatchEventDispatchedListener.class.getClass();
ReactNativeConfig.class.getClass();
IntBufferBatchMountItem.class.getClass();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,13 @@
import com.facebook.react.fabric.events.EventEmitterWrapper;
import com.facebook.react.fabric.events.FabricEventEmitter;
import com.facebook.react.fabric.mounting.MountingManager;
import com.facebook.react.fabric.mounting.mountitems.BatchMountItem;
import com.facebook.react.fabric.mounting.mountitems.CreateMountItem;
import com.facebook.react.fabric.mounting.mountitems.DispatchCommandMountItem;
import com.facebook.react.fabric.mounting.mountitems.DispatchIntCommandMountItem;
import com.facebook.react.fabric.mounting.mountitems.DispatchStringCommandMountItem;
import com.facebook.react.fabric.mounting.mountitems.InsertMountItem;
import com.facebook.react.fabric.mounting.mountitems.IntBufferBatchMountItem;
import com.facebook.react.fabric.mounting.mountitems.MountItem;
import com.facebook.react.fabric.mounting.mountitems.PreAllocateViewMountItem;
import com.facebook.react.fabric.mounting.mountitems.RemoveDeleteMultiMountItem;
import com.facebook.react.fabric.mounting.mountitems.SendAccessibilityEvent;
import com.facebook.react.fabric.mounting.mountitems.UpdateEventEmitterMountItem;
import com.facebook.react.fabric.mounting.mountitems.UpdateLayoutMountItem;
import com.facebook.react.fabric.mounting.mountitems.UpdatePaddingMountItem;
import com.facebook.react.fabric.mounting.mountitems.UpdatePropsMountItem;
import com.facebook.react.fabric.mounting.mountitems.UpdateStateMountItem;
import com.facebook.react.modules.core.ReactChoreographer;
import com.facebook.react.modules.i18nmanager.I18nUtil;
import com.facebook.react.uimanager.PixelUtil;
Expand Down Expand Up @@ -352,100 +343,6 @@ private void preallocateView(
isLayoutable));
}

@DoNotStrip
@SuppressWarnings("unused")
@AnyThread
@ThreadConfined(ANY)
private MountItem createMountItem(
String componentName,
@Nullable ReadableMap props,
@Nullable Object stateWrapper,
int reactRootTag,
int reactTag,
boolean isLayoutable) {
String component = getFabricComponentName(componentName);

// This could be null if teardown/navigation away from a surface on the main thread happens
// while a commit is being processed in a different thread. By contract we expect this to be
// possible at teardown, but this race should *never* happen at startup.
@Nullable ThemedReactContext reactContext = mReactContextForRootTag.get(reactRootTag);

return new CreateMountItem(
reactContext,
reactRootTag,
reactTag,
component,
props,
(StateWrapper) stateWrapper,
isLayoutable);
}

@DoNotStrip
@SuppressWarnings("unused")
@AnyThread
@ThreadConfined(ANY)
private MountItem insertMountItem(int reactTag, int parentReactTag, int index) {
return new InsertMountItem(reactTag, parentReactTag, index);
}

@DoNotStrip
@SuppressWarnings("unused")
@AnyThread
@ThreadConfined(ANY)
private MountItem removeDeleteMultiMountItem(int[] metadata) {
return new RemoveDeleteMultiMountItem(metadata);
}

@DoNotStrip
@SuppressWarnings("unused")
@AnyThread
@ThreadConfined(ANY)
private MountItem updateLayoutMountItem(
int reactTag, int x, int y, int width, int height, int layoutDirection) {
return new UpdateLayoutMountItem(reactTag, x, y, width, height, layoutDirection);
}

@DoNotStrip
@SuppressWarnings("unused")
@AnyThread
@ThreadConfined(ANY)
private MountItem updatePaddingMountItem(int reactTag, int left, int top, int right, int bottom) {
return new UpdatePaddingMountItem(reactTag, left, top, right, bottom);
}

@DoNotStrip
@SuppressWarnings("unused")
@AnyThread
@ThreadConfined(ANY)
private MountItem updatePropsMountItem(int reactTag, ReadableMap map) {
return new UpdatePropsMountItem(reactTag, map);
}

@DoNotStrip
@SuppressWarnings("unused")
@AnyThread
@ThreadConfined(ANY)
private MountItem updateStateMountItem(int reactTag, @Nullable Object stateWrapper) {
return new UpdateStateMountItem(reactTag, (StateWrapper) stateWrapper);
}

@DoNotStrip
@SuppressWarnings("unused")
@AnyThread
@ThreadConfined(ANY)
private MountItem updateEventEmitterMountItem(int reactTag, Object eventEmitter) {
return new UpdateEventEmitterMountItem(reactTag, (EventEmitterWrapper) eventEmitter);
}

@DoNotStrip
@SuppressWarnings("unused")
@AnyThread
@ThreadConfined(ANY)
private MountItem createBatchMountItem(
int rootTag, MountItem[] items, int size, int commitNumber) {
return new BatchMountItem(rootTag, items, size, commitNumber);
}

@DoNotStrip
@SuppressWarnings("unused")
@AnyThread
Expand Down Expand Up @@ -599,7 +496,7 @@ public void synchronouslyUpdateViewOnUIThread(
@Override
public void execute(@NonNull MountingManager mountingManager) {
try {
updatePropsMountItem(reactTag, props).execute(mountingManager);
mountingManager.updateProps(reactTag, props);
} catch (Exception ex) {
// TODO T42943890: Fix animations in Fabric and remove this try/catch
ReactSoftException.logSoftException(
Expand Down Expand Up @@ -664,12 +561,9 @@ private void scheduleMountItem(
// When Binding.cpp calls scheduleMountItems during a commit phase, it always calls with
// a BatchMountItem. No other sites call into this with a BatchMountItem, and Binding.cpp only
// calls scheduleMountItems with a BatchMountItem.
boolean isClassicBatchMountItem = mountItem instanceof BatchMountItem;
boolean isIntBufferMountItem = mountItem instanceof IntBufferBatchMountItem;
boolean isBatchMountItem = isClassicBatchMountItem || isIntBufferMountItem;
boolean isBatchMountItem = mountItem instanceof IntBufferBatchMountItem;
boolean shouldSchedule =
(isClassicBatchMountItem && ((BatchMountItem) mountItem).shouldSchedule())
|| (isIntBufferMountItem && ((IntBufferBatchMountItem) mountItem).shouldSchedule())
(isBatchMountItem && ((IntBufferBatchMountItem) mountItem).shouldSchedule())
|| (!isBatchMountItem && mountItem != null);

// In case of sync rendering, this could be called on the UI thread. Otherwise,
Expand Down Expand Up @@ -939,16 +833,6 @@ private boolean dispatchMountItems() {
}

try {
// Make sure surface associated with this MountItem has been started, and not stopped.
// TODO T68118357: clean up this logic and simplify this method overall
if (mountItem instanceof BatchMountItem) {
BatchMountItem batchMountItem = (BatchMountItem) mountItem;
if (!isSurfaceActiveForExecution(
batchMountItem.getRootTag(), "dispatchMountItems BatchMountItem")) {
continue;
}
}

// Make sure surface associated with this MountItem has been started, and not stopped.
// TODO T68118357: clean up this logic and simplify this method overall
if (mountItem instanceof IntBufferBatchMountItem) {
Expand Down
Loading

0 comments on commit 0db56f1

Please sign in to comment.