From 7720613bda49a821c926b2f7d55333b430581031 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Sun, 3 Mar 2019 15:47:08 -0800 Subject: [PATCH] Add systraces for pre-mountItems executed during commit Summary: Now that pre-allocation of views update props, we can just force the execution of "pre-allocation" instead of "create" mount item. This diff adds systraces to the execution of pre-mountItems during commit This should reduce the amount of mountItems that are created during commit phase. This should improve TTI (I'm running a MobileLab) Reviewed By: shergin Differential Revision: D14297478 fbshipit-source-id: d8e515d34cf6edacce53c0903f74a08029259f6f --- .../react/fabric/FabricUIManager.java | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index cfaa9e45a10..9023b399d22 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -18,7 +18,6 @@ import android.os.SystemClock; import android.support.annotation.GuardedBy; import android.support.annotation.Nullable; import android.support.annotation.UiThread; -import android.util.Log; import android.view.View; import com.facebook.common.logging.FLog; import com.facebook.infer.annotation.ThreadConfined; @@ -105,14 +104,15 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { private List mMountItems = new ArrayList<>(); @GuardedBy("mPreMountItemsLock") - private ArrayDeque mPreMountItems = new ArrayDeque<>( - PRE_MOUNT_ITEMS_INITIAL_SIZE_ARRAY); + private ArrayDeque mPreMountItems = + new ArrayDeque<>(PRE_MOUNT_ITEMS_INITIAL_SIZE_ARRAY); @ThreadConfined(UI) private final DispatchUIFrameCallback mDispatchUIFrameCallback; @ThreadConfined(UI) private boolean mIsMountingEnabled = true; + private long mRunStartTime = 0l; private long mBatchedExecutionTime = 0l; private long mNonBatchedExecutionTime = 0l; @@ -193,7 +193,12 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { } @DoNotStrip - private void preallocateView(int rootTag, int reactTag, final String componentName, ReadableMap props, boolean isLayoutable) { + private void preallocateView( + int rootTag, + int reactTag, + final String componentName, + ReadableMap props, + boolean isLayoutable) { if (UiThreadUtil.isOnUiThread()) { // There is no reason to allocate views ahead of time on the main thread. return; @@ -202,7 +207,8 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { ThemedReactContext context = mReactContextForRootTag.get(rootTag); String component = sComponentNames.get(componentName); synchronized (mPreMountItemsLock) { - mPreMountItems.add(new PreAllocateViewMountItem(context, rootTag, reactTag, component, props, isLayoutable)); + mPreMountItems.add( + new PreAllocateViewMountItem(context, rootTag, reactTag, component, props, isLayoutable)); } } @@ -323,7 +329,6 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { mMountItems = new ArrayList<>(); } - // If there are MountItems to dispatch, we make sure all the "pre mount items" are executed ArrayDeque mPreMountItemsToDispatch = null; synchronized (mPreMountItemsLock) { @@ -332,15 +337,22 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { mPreMountItems = new ArrayDeque<>(PRE_MOUNT_ITEMS_INITIAL_SIZE_ARRAY); } } + if (mPreMountItemsToDispatch != null) { + Systrace.beginSection( + Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, + "FabricUIManager::mountViews preMountItems to execute: " + + mPreMountItemsToDispatch.size()); - while (mPreMountItemsToDispatch != null && !mPreMountItemsToDispatch.isEmpty()) { - mPreMountItemsToDispatch.pollFirst().execute(mMountingManager); + while (!mPreMountItemsToDispatch.isEmpty()) { + mPreMountItemsToDispatch.pollFirst().execute(mMountingManager); + } + + Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); } - Systrace.beginSection( Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, - "FabricUIManager::mountViews (" + mountItemsToDispatch.size() + " batches)"); + "FabricUIManager::mountViews mountItems to execute: " + mountItemsToDispatch.size()); long batchedExecutionStartTime = SystemClock.uptimeMillis(); for (MountItem mountItem : mountItemsToDispatch) { @@ -353,9 +365,7 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { @UiThread private void dispatchPreMountItems(long frameTimeNanos) { long nonBatchedExecutionStartTime = SystemClock.uptimeMillis(); - Systrace.beginSection( - Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, - "FabricUIManager::premountViews"); + Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricUIManager::premountViews"); while (true) { long timeLeftInFrame = FRAME_TIME_MS - ((System.nanoTime() - frameTimeNanos) / 1000000);