From b9be9a01a9fbd871956b6216628e83e42cbeca64 Mon Sep 17 00:00:00 2001 From: Alexey Lang Date: Thu, 21 Sep 2017 07:56:17 -0700 Subject: [PATCH] Break down PRE_REACT_CONTEXT Reviewed By: cwdick Differential Revision: D5874529 fbshipit-source-id: 0ee9d740b4445419e3143942514475751763520d --- .../facebook/react/ReactInstanceManager.java | 103 ++++++++++-------- .../react/bridge/ReactMarkerConstants.java | 2 + 2 files changed, 58 insertions(+), 47 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java index d7cf0c8a7..7d17f920c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java @@ -23,6 +23,8 @@ import static com.facebook.react.bridge.ReactMarkerConstants.PRE_SETUP_REACT_CON import static com.facebook.react.bridge.ReactMarkerConstants.PRE_SETUP_REACT_CONTEXT_START; import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_PACKAGES_END; import static com.facebook.react.bridge.ReactMarkerConstants.PROCESS_PACKAGES_START; +import static com.facebook.react.bridge.ReactMarkerConstants.REACT_CONTEXT_THREAD_END; +import static com.facebook.react.bridge.ReactMarkerConstants.REACT_CONTEXT_THREAD_START; import static com.facebook.react.bridge.ReactMarkerConstants.SETUP_REACT_CONTEXT_END; import static com.facebook.react.bridge.ReactMarkerConstants.SETUP_REACT_CONTEXT_START; import static com.facebook.systrace.Systrace.TRACE_TAG_REACT_APPS; @@ -856,56 +858,63 @@ public class ReactInstanceManager { } } - mCreateReactContextThread = new Thread(new Runnable() { - @Override - public void run() { - synchronized (ReactInstanceManager.this.mHasStartedDestroying) { - while (ReactInstanceManager.this.mHasStartedDestroying) { - try { - ReactInstanceManager.this.mHasStartedDestroying.wait(); - } catch (InterruptedException e) { - continue; - } - } - } - // As destroy() may have run and set this to false, ensure that it is true before we create - mHasStartedCreatingInitialContext = true; + mCreateReactContextThread = + new Thread( + new Runnable() { + @Override + public void run() { + ReactMarker.logMarker(REACT_CONTEXT_THREAD_END); + synchronized (ReactInstanceManager.this.mHasStartedDestroying) { + while (ReactInstanceManager.this.mHasStartedDestroying) { + try { + ReactInstanceManager.this.mHasStartedDestroying.wait(); + } catch (InterruptedException e) { + continue; + } + } + } + // As destroy() may have run and set this to false, ensure that it is true before we create + mHasStartedCreatingInitialContext = true; - try { - Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY); - final ReactApplicationContext reactApplicationContext = createReactContext( - initParams.getJsExecutorFactory().create(), - initParams.getJsBundleLoader()); + try { + Process.setThreadPriority(Process.THREAD_PRIORITY_DISPLAY); + final ReactApplicationContext reactApplicationContext = + createReactContext( + initParams.getJsExecutorFactory().create(), + initParams.getJsBundleLoader()); - mCreateReactContextThread = null; - ReactMarker.logMarker(PRE_SETUP_REACT_CONTEXT_START); - final Runnable maybeRecreateReactContextRunnable = new Runnable() { - @Override - public void run() { - if (mPendingReactContextInitParams != null) { - runCreateReactContextOnNewThread(mPendingReactContextInitParams); - mPendingReactContextInitParams = null; + mCreateReactContextThread = null; + ReactMarker.logMarker(PRE_SETUP_REACT_CONTEXT_START); + final Runnable maybeRecreateReactContextRunnable = + new Runnable() { + @Override + public void run() { + if (mPendingReactContextInitParams != null) { + runCreateReactContextOnNewThread(mPendingReactContextInitParams); + mPendingReactContextInitParams = null; + } + } + }; + Runnable setupReactContextRunnable = + new Runnable() { + @Override + public void run() { + try { + setupReactContext(reactApplicationContext); + } catch (Exception e) { + mDevSupportManager.handleException(e); + } + } + }; + + reactApplicationContext.runOnNativeModulesQueueThread(setupReactContextRunnable); + UiThreadUtil.runOnUiThread(maybeRecreateReactContextRunnable); + } catch (Exception e) { + mDevSupportManager.handleException(e); + } } - } - }; - Runnable setupReactContextRunnable = new Runnable() { - @Override - public void run() { - try { - setupReactContext(reactApplicationContext); - } catch (Exception e) { - mDevSupportManager.handleException(e); - } - } - }; - - reactApplicationContext.runOnNativeModulesQueueThread(setupReactContextRunnable); - UiThreadUtil.runOnUiThread(maybeRecreateReactContextRunnable); - } catch (Exception e) { - mDevSupportManager.handleException(e); - } - } - }); + }); + ReactMarker.logMarker(REACT_CONTEXT_THREAD_START); mCreateReactContextThread.start(); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarkerConstants.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarkerConstants.java index b6ac80f62..e3336fbcc 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarkerConstants.java +++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactMarkerConstants.java @@ -70,4 +70,6 @@ public enum ReactMarkerConstants { RELOAD, DOWNLOAD_START, DOWNLOAD_END, + REACT_CONTEXT_THREAD_START, + REACT_CONTEXT_THREAD_END, }