Add perf markers for cold start
Summary: public Adds useful systrace perf markers for cold start analysis Reviewed By: mikearmstrong001 Differential Revision: D2695629 fb-gh-sync-id: d964f28a1f3e10a13c441a17b0300c980d4914e8
This commit is contained in:
parent
388d8c8f9b
commit
ca016e4eb3
|
@ -32,6 +32,7 @@ import com.facebook.react.uimanager.UIManagerModule;
|
|||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.react.uimanager.debug.DebugComponentOwnershipModule;
|
||||
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
||||
import com.facebook.systrace.Systrace;
|
||||
|
||||
/**
|
||||
* Package defining core framework modules (e.g. UIManager). It should be used for modules that
|
||||
|
@ -53,6 +54,16 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|||
@Override
|
||||
public List<NativeModule> createNativeModules(
|
||||
ReactApplicationContext catalystApplicationContext) {
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createUIManagerModule");
|
||||
UIManagerModule uiManagerModule;
|
||||
try {
|
||||
uiManagerModule = new UIManagerModule(
|
||||
catalystApplicationContext,
|
||||
mReactInstanceManager.createAllViewManagers(catalystApplicationContext));
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
return Arrays.<NativeModule>asList(
|
||||
new AnimationsDebugModule(
|
||||
catalystApplicationContext,
|
||||
|
@ -64,9 +75,7 @@ import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|||
new SourceCodeModule(
|
||||
mReactInstanceManager.getSourceUrl(),
|
||||
mReactInstanceManager.getDevSupportManager().getSourceMapUrl()),
|
||||
new UIManagerModule(
|
||||
catalystApplicationContext,
|
||||
mReactInstanceManager.createAllViewManagers(catalystApplicationContext)),
|
||||
uiManagerModule,
|
||||
new DebugComponentOwnershipModule(catalystApplicationContext));
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ import com.facebook.react.uimanager.ReactNative;
|
|||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.ViewManager;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import com.facebook.systrace.Systrace;
|
||||
|
||||
/**
|
||||
* This class is managing instances of {@link CatalystInstance}. It expose a way to configure
|
||||
|
@ -465,11 +466,16 @@ import com.facebook.soloader.SoLoader;
|
|||
@Override
|
||||
public List<ViewManager> createAllViewManagers(
|
||||
ReactApplicationContext catalystApplicationContext) {
|
||||
List<ViewManager> allViewManagers = new ArrayList<>();
|
||||
for (ReactPackage reactPackage : mPackages) {
|
||||
allViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createAllViewManagers");
|
||||
try {
|
||||
List<ViewManager> allViewManagers = new ArrayList<>();
|
||||
for (ReactPackage reactPackage : mPackages) {
|
||||
allViewManagers.addAll(reactPackage.createViewManagers(catalystApplicationContext));
|
||||
}
|
||||
return allViewManagers;
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
return allViewManagers;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
@ -586,30 +592,73 @@ import com.facebook.soloader.SoLoader;
|
|||
reactContext.setNativeModuleCallExceptionHandler(mDevSupportManager);
|
||||
}
|
||||
|
||||
CoreModulesPackage coreModulesPackage =
|
||||
new CoreModulesPackage(this, mBackBtnHandler);
|
||||
processPackage(coreModulesPackage, reactContext, nativeRegistryBuilder, jsModulesBuilder);
|
||||
Systrace.beginSection(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"createAndProcessCoreModulesPackage");
|
||||
try {
|
||||
CoreModulesPackage coreModulesPackage =
|
||||
new CoreModulesPackage(this, mBackBtnHandler);
|
||||
processPackage(coreModulesPackage, reactContext, nativeRegistryBuilder, jsModulesBuilder);
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
// TODO(6818138): Solve use-case of native/js modules overriding
|
||||
for (ReactPackage reactPackage : mPackages) {
|
||||
processPackage(reactPackage, reactContext, nativeRegistryBuilder, jsModulesBuilder);
|
||||
Systrace.beginSection(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"createAndProcessCustomReactPackage");
|
||||
try {
|
||||
processPackage(reactPackage, reactContext, nativeRegistryBuilder, jsModulesBuilder);
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
}
|
||||
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "buildNativeModuleRegistry");
|
||||
NativeModuleRegistry nativeModuleRegistry;
|
||||
try {
|
||||
nativeModuleRegistry = nativeRegistryBuilder.build();
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "buildJSModuleConfig");
|
||||
JavaScriptModulesConfig javaScriptModulesConfig;
|
||||
try {
|
||||
javaScriptModulesConfig = jsModulesBuilder.build();
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
CatalystInstanceImpl.Builder catalystInstanceBuilder = new CatalystInstanceImpl.Builder()
|
||||
.setCatalystQueueConfigurationSpec(CatalystQueueConfigurationSpec.createDefault())
|
||||
.setJSExecutor(jsExecutor)
|
||||
.setRegistry(nativeRegistryBuilder.build())
|
||||
.setJSModulesConfig(jsModulesBuilder.build())
|
||||
.setRegistry(nativeModuleRegistry)
|
||||
.setJSModulesConfig(javaScriptModulesConfig)
|
||||
.setJSBundleLoader(jsBundleLoader)
|
||||
.setNativeModuleCallExceptionHandler(mDevSupportManager);
|
||||
|
||||
CatalystInstance catalystInstance = catalystInstanceBuilder.build();
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "createCatalystInstance");
|
||||
CatalystInstance catalystInstance;
|
||||
try {
|
||||
catalystInstance = catalystInstanceBuilder.build();
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
if (mBridgeIdleDebugListener != null) {
|
||||
catalystInstance.addBridgeIdleDebugListener(mBridgeIdleDebugListener);
|
||||
}
|
||||
|
||||
reactContext.initializeWithInstance(catalystInstance);
|
||||
catalystInstance.runJSBundle();
|
||||
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "runJSBundle");
|
||||
try {
|
||||
catalystInstance.runJSBundle();
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
return reactContext;
|
||||
}
|
||||
|
|
|
@ -88,8 +88,13 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
initializeBridge(jsExecutor, jsModulesConfig);
|
||||
initLatch.countDown();
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "initializeBridge");
|
||||
try {
|
||||
initializeBridge(jsExecutor, jsModulesConfig);
|
||||
initLatch.countDown();
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -108,22 +113,31 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
mCatalystQueueConfiguration.getJSQueueThread().assertIsOnThread();
|
||||
Assertions.assertCondition(mBridge == null, "initializeBridge should be called once");
|
||||
|
||||
mBridge = new ReactBridge(
|
||||
jsExecutor,
|
||||
new NativeModulesReactCallback(),
|
||||
mCatalystQueueConfiguration.getNativeModulesQueueThread());
|
||||
mBridge.setGlobalVariable(
|
||||
"__fbBatchedBridgeConfig",
|
||||
buildModulesConfigJSONProperty(mJavaRegistry, jsModulesConfig));
|
||||
Systrace.registerListener(mTraceListener);
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactBridgeCtor");
|
||||
try {
|
||||
mBridge = new ReactBridge(
|
||||
jsExecutor,
|
||||
new NativeModulesReactCallback(),
|
||||
mCatalystQueueConfiguration.getNativeModulesQueueThread());
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "setBatchedBridgeConfig");
|
||||
try {
|
||||
mBridge.setGlobalVariable(
|
||||
"__fbBatchedBridgeConfig",
|
||||
buildModulesConfigJSONProperty(mJavaRegistry, jsModulesConfig));
|
||||
mBridge.setGlobalVariable(
|
||||
"__RCTProfileIsProfiling",
|
||||
Systrace.isTracing(Systrace.TRACE_TAG_REACT_APPS) ? "true" : "false");
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runJSBundle() {
|
||||
Systrace.beginSection(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
|
||||
"CatalystInstance_runJSBundle");
|
||||
|
||||
try {
|
||||
final CountDownLatch initLatch = new CountDownLatch(1);
|
||||
mCatalystQueueConfiguration.getJSQueueThread().runOnQueue(
|
||||
|
@ -135,10 +149,16 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
|
||||
incrementPendingJSCalls();
|
||||
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "loadJSScript");
|
||||
try {
|
||||
mJSBundleLoader.loadScript(mBridge);
|
||||
|
||||
// This is registered after JS starts since it makes a JS call
|
||||
Systrace.registerListener(mTraceListener);
|
||||
} catch (JSExecutionException e) {
|
||||
mNativeModuleCallExceptionHandler.handleException(e);
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
|
||||
initLatch.countDown();
|
||||
|
@ -149,8 +169,6 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||
"Timed out loading JS!");
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.io.IOException;
|
|||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -186,32 +185,38 @@ public class NativeModuleRegistry {
|
|||
}
|
||||
|
||||
public NativeModuleRegistry build() {
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
StringWriter writer = new StringWriter();
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateJSON");
|
||||
String moduleDefinitionJson;
|
||||
try {
|
||||
JsonGenerator jg = jsonFactory.createGenerator(writer);
|
||||
jg.writeStartObject();
|
||||
for (ModuleDefinition module : mModuleDefinitions) {
|
||||
jg.writeObjectFieldStart(module.name);
|
||||
jg.writeNumberField("moduleID", module.id);
|
||||
jg.writeObjectFieldStart("methods");
|
||||
for (int i = 0; i < module.methods.size(); i++) {
|
||||
MethodRegistration method = module.methods.get(i);
|
||||
jg.writeObjectFieldStart(method.name);
|
||||
jg.writeNumberField("methodID", i);
|
||||
jg.writeStringField("type", method.method.getType());
|
||||
JsonFactory jsonFactory = new JsonFactory();
|
||||
StringWriter writer = new StringWriter();
|
||||
try {
|
||||
JsonGenerator jg = jsonFactory.createGenerator(writer);
|
||||
jg.writeStartObject();
|
||||
for (ModuleDefinition module : mModuleDefinitions) {
|
||||
jg.writeObjectFieldStart(module.name);
|
||||
jg.writeNumberField("moduleID", module.id);
|
||||
jg.writeObjectFieldStart("methods");
|
||||
for (int i = 0; i < module.methods.size(); i++) {
|
||||
MethodRegistration method = module.methods.get(i);
|
||||
jg.writeObjectFieldStart(method.name);
|
||||
jg.writeNumberField("methodID", i);
|
||||
jg.writeStringField("type", method.method.getType());
|
||||
jg.writeEndObject();
|
||||
}
|
||||
jg.writeEndObject();
|
||||
module.target.writeConstantsField(jg, "constants");
|
||||
jg.writeEndObject();
|
||||
}
|
||||
jg.writeEndObject();
|
||||
module.target.writeConstantsField(jg, "constants");
|
||||
jg.writeEndObject();
|
||||
jg.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("Unable to serialize Java module configuration", ioe);
|
||||
}
|
||||
jg.writeEndObject();
|
||||
jg.close();
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("Unable to serialize Java module configuration", ioe);
|
||||
moduleDefinitionJson = writer.getBuffer().toString();
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
String moduleDefinitionJson = writer.getBuffer().toString();
|
||||
return new NativeModuleRegistry(mModuleDefinitions, mModuleInstances, moduleDefinitionJson);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,10 +106,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
|||
mShadowNodeRegistry);
|
||||
DisplayMetrics displayMetrics = reactContext.getResources().getDisplayMetrics();
|
||||
DisplayMetricsHolder.setDisplayMetrics(displayMetrics);
|
||||
|
||||
mModuleConstants = UIManagerModuleConstantsHelper.createConstants(
|
||||
displayMetrics,
|
||||
viewManagerList);
|
||||
mModuleConstants = createConstants(displayMetrics, viewManagerList);
|
||||
reactContext.addLifecycleEventListener(this);
|
||||
}
|
||||
|
||||
|
@ -143,6 +140,19 @@ public class UIManagerModule extends ReactContextBaseJavaModule implements
|
|||
mEventDispatcher.onCatalystInstanceDestroyed();
|
||||
}
|
||||
|
||||
private static Map<String, Object> createConstants(
|
||||
DisplayMetrics displayMetrics,
|
||||
List<ViewManager> viewManagerList) {
|
||||
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "CreateUIManagerConstants");
|
||||
try {
|
||||
return UIManagerModuleConstantsHelper.createConstants(
|
||||
displayMetrics,
|
||||
viewManagerList);
|
||||
} finally {
|
||||
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new root view. JS can use the returned tag with manageChildren to add/remove
|
||||
* children to this view.
|
||||
|
|
Loading…
Reference in New Issue