Skip to content

Commit

Permalink
Better instrument the startup timeline.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Benoit Girard authored and facebook-github-bot committed Oct 11, 2024
1 parent 54c29a7 commit 401991c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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
Expand Down Expand Up @@ -102,35 +103,41 @@ public String getMainComponentName() {
}

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 401991c

Please sign in to comment.