Initialize JS executor and context at loadApp time

Summary: Automatically starts loading the RN instance as soon as loadApp is called instead of waiting for the UI to be constructed and attached to the window. This saves ~75ms of cold start time on GN 2011 phones.

Also, updates the contract for createReactContextInBackground such that it is only called once (so that people don't accidentally initialize more than once).

See http://imgur.com/a/d7qVm for systrace visualization.

public

Reviewed By: kmagiera

Differential Revision: D2652279

fb-gh-sync-id: 6e7b1fa5dea091af0d568834e11ed23eb1a7860e
This commit is contained in:
Andy Street
2015-11-18 11:19:31 -08:00
committed by facebook-github-bot-7
parent fea59168cc
commit 530ee3eeac
2 changed files with 48 additions and 1 deletions

View File

@@ -295,6 +295,8 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
ReactInstanceManager reactInstanceManager,
String moduleName,
@Nullable Bundle launchOptions) {
UiThreadUtil.assertOnUiThread();
// TODO(6788889): Use POJO instead of bundle here, apparently we can't just use WritableMap
// here as it may be deallocated in native after passing via JNI bridge, but we want to reuse
// it in the case of re-creating the catalyst instance
@@ -307,6 +309,10 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
mJSModuleName = moduleName;
mLaunchOptions = launchOptions;
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
mReactInstanceManager.createReactContextInBackground();
}
// We need to wait for the initial onMeasure, if this view has not yet been measured, we set
// mAttachScheduled flag, which will make this view startReactApplication itself to instance
// manager once onMeasure is called.