From 2e42cc76521ba5bf3692e806eef2d3e64d5ffa1a Mon Sep 17 00:00:00 2001 From: David Vacca Date: Sun, 24 Feb 2019 11:55:50 -0800 Subject: [PATCH] optimize calls to updateRootLayoutSpecs Summary: This diff changes the onMeasure method of the RootView to optimize the amount of times we call updateRootLayoutSpecs in Fabric Reviewed By: shergin Differential Revision: D14198155 fbshipit-source-id: ff2deee04540899c25d4e38b0bd93333f74c6ace --- .../src/main/java/com/facebook/react/ReactRootView.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index 83bdf1d6e5b..3f8d29affcf 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -91,6 +91,8 @@ public class ReactRootView extends FrameLayout implements RootView { private boolean mWasMeasured = false; private int mWidthMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); private int mHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + private int mLastWidth = 0; + private int mLastHeight = 0; private @UIManagerType int mUIManagerType = DEFAULT; public ReactRootView(Context context) { @@ -116,6 +118,8 @@ public class ReactRootView extends FrameLayout implements RootView { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Systrace.beginSection(TRACE_TAG_REACT_JAVA_BRIDGE, "ReactRootView.onMeasure"); try { + boolean measureSpecsUpdated = widthMeasureSpec != mWidthMeasureSpec || + heightMeasureSpec != mHeightMeasureSpec; mWidthMeasureSpec = widthMeasureSpec; mHeightMeasureSpec = heightMeasureSpec; @@ -155,9 +159,11 @@ public class ReactRootView extends FrameLayout implements RootView { // Check if we were waiting for onMeasure to attach the root view. if (mReactInstanceManager != null && !mIsAttachedToInstance) { attachToReactInstanceManager(); - } else { + } else if (measureSpecsUpdated || mLastWidth != width || mLastHeight != height) { updateRootLayoutSpecs(mWidthMeasureSpec, mHeightMeasureSpec); } + mLastWidth = width; + mLastHeight = height; } finally { Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);