Better instrument the startup timeline.

Summary:
Using a new JVM profiler (D64128815) to find blind spot in the early startup init markers and adding them.

Changelog: [Internal]

Reviewed By: rubennorte

Differential Revision: D64141515

fbshipit-source-id: d2968ed5dafdd891b8cc5a6115479c0678bfdc80
This commit is contained in:
Benoit Girard
2024-10-11 12:50:28 -07:00
committed by Facebook GitHub Bot
parent 54c29a7acf
commit 401991c3f0
2 changed files with 46 additions and 29 deletions
@@ -20,6 +20,7 @@ import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.Callback;
import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags;
import com.facebook.react.modules.core.PermissionListener;
import com.facebook.systrace.Systrace;
/**
* Delegate class for {@link ReactActivity}. You can subclass this to provide custom implementations
@@ -102,35 +103,41 @@ public class ReactActivityDelegate {
}
public void onCreate(Bundle savedInstanceState) {
String mainComponentName = getMainComponentName();
final Bundle launchOptions = composeLaunchOptions();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isWideColorGamutEnabled()) {
mActivity.getWindow().setColorMode(ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT);
}
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactDelegate =
new ReactDelegate(getPlainActivity(), getReactHost(), mainComponentName, launchOptions);
} else {
mReactDelegate =
new ReactDelegate(
getPlainActivity(),
getReactNativeHost(),
mainComponentName,
launchOptions,
isFabricEnabled()) {
@Override
protected ReactRootView createRootView() {
ReactRootView rootView = ReactActivityDelegate.this.createRootView();
if (rootView == null) {
rootView = super.createRootView();
}
return rootView;
}
};
}
if (mainComponentName != null) {
loadApp(mainComponentName);
}
Systrace.traceSection(
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE,
"ReactActivityDelegate.onCreate::init",
() -> {
String mainComponentName = getMainComponentName();
final Bundle launchOptions = composeLaunchOptions();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isWideColorGamutEnabled()) {
mActivity.getWindow().setColorMode(ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT);
}
if (ReactNativeFeatureFlags.enableBridgelessArchitecture()) {
mReactDelegate =
new ReactDelegate(
getPlainActivity(), getReactHost(), mainComponentName, launchOptions);
} else {
mReactDelegate =
new ReactDelegate(
getPlainActivity(),
getReactNativeHost(),
mainComponentName,
launchOptions,
isFabricEnabled()) {
@Override
protected ReactRootView createRootView() {
ReactRootView rootView = ReactActivityDelegate.this.createRootView();
if (rootView == null) {
rootView = super.createRootView();
}
return rootView;
}
};
}
if (mainComponentName != null) {
loadApp(mainComponentName);
}
});
}
protected void loadApp(String appKey) {
@@ -31,6 +31,16 @@ public object Systrace {
@JvmStatic public fun traceInstant(tag: Long, title: String?, scope: EventScope?): Unit = Unit
@JvmStatic
public fun traceSection(tag: Long, sectionName: String, block: () -> T) {
beginSection(sectionName)
try {
return block()
} finally {
endSection(sectionName)
}
}
@JvmStatic
public fun beginSection(tag: Long, sectionName: String) {
Trace.beginSection(sectionName)