Commit 980a173e authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Load native libraries earlier in startup

This change kicks off native library loading as early as possible in a
separate thread, to reduce startup latency. There may be a few
activities that don't actually need native libs, but the vast majority
of the time we end up loading the native lib, and this seems like a good
trade off for the perf improvements.

Pinpoint results for messageloop_start_time in mobile.startup:
Android Go:
Cold start: -11.3% https://pinpoint-dot-chromeperf.appspot.com/job/10e6fbf3520000
Warm start: -23%: https://pinpoint-dot-chromeperf.appspot.com/job/1227a4cd520000

Pixel 2:
Cold start: -0.3% https://pinpoint-dot-chromeperf.appspot.com/job/11822b23520000
Warm start: -1.7% https://pinpoint-dot-chromeperf.appspot.com/job/154a85cb520000

Bug: 1148803
Change-Id: I70256509cad47c20ec047222ba7bd0f576abe548
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2535732
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827862}
parent c25c700a
...@@ -21,6 +21,7 @@ import org.chromium.base.LocaleUtils; ...@@ -21,6 +21,7 @@ import org.chromium.base.LocaleUtils;
import org.chromium.base.PathUtils; import org.chromium.base.PathUtils;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
import org.chromium.base.annotations.MainDex; import org.chromium.base.annotations.MainDex;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.memory.MemoryPressureMonitor; import org.chromium.base.memory.MemoryPressureMonitor;
import org.chromium.chrome.browser.background_task_scheduler.ChromeBackgroundTaskFactory; import org.chromium.chrome.browser.background_task_scheduler.ChromeBackgroundTaskFactory;
import org.chromium.chrome.browser.base.MainDexApplicationImpl; import org.chromium.chrome.browser.base.MainDexApplicationImpl;
...@@ -151,6 +152,17 @@ public class ChromeApplication extends SplitCompatApplication { ...@@ -151,6 +152,17 @@ public class ChromeApplication extends SplitCompatApplication {
} }
} }
@Override
public void onCreate() {
super.onCreate();
if (SplitCompatApplication.isBrowserProcess()
&& CachedFeatureFlags.isEnabled(ChromeFeatureList.EARLY_LIBRARY_LOAD)) {
// Kick off library loading in a separate thread so it's ready when we need it.
new Thread(() -> LibraryLoader.getInstance().ensureMainDexInitialized()).start();
}
}
private static Boolean shouldUseDebugFlags() { private static Boolean shouldUseDebugFlags() {
return CachedFeatureFlags.isEnabled(ChromeFeatureList.COMMAND_LINE_ON_NON_ROOTED); return CachedFeatureFlags.isEnabled(ChromeFeatureList.COMMAND_LINE_ON_NON_ROOTED);
} }
......
...@@ -57,6 +57,7 @@ public class ChromeCachedFlags { ...@@ -57,6 +57,7 @@ public class ChromeCachedFlags {
ChromeFeatureList.COMMAND_LINE_ON_NON_ROOTED, ChromeFeatureList.COMMAND_LINE_ON_NON_ROOTED,
ChromeFeatureList.CONDITIONAL_TAB_STRIP_ANDROID, ChromeFeatureList.CONDITIONAL_TAB_STRIP_ANDROID,
ChromeFeatureList.DOWNLOADS_AUTO_RESUMPTION_NATIVE, ChromeFeatureList.DOWNLOADS_AUTO_RESUMPTION_NATIVE,
ChromeFeatureList.EARLY_LIBRARY_LOAD,
ChromeFeatureList.HORIZONTAL_TAB_SWITCHER_ANDROID, ChromeFeatureList.HORIZONTAL_TAB_SWITCHER_ANDROID,
ChromeFeatureList.IMMERSIVE_UI_MODE, ChromeFeatureList.IMMERSIVE_UI_MODE,
ChromeFeatureList.INSTANT_START, ChromeFeatureList.INSTANT_START,
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
#include "chrome/browser/chrome_browser_field_trials_mobile.h" #include "chrome/browser/chrome_browser_field_trials_mobile.h"
#include "chrome/browser/flags/android/cached_feature_flags.h" #include "chrome/browser/flags/android/cached_feature_flags.h"
#include "chrome/common/chrome_features.h"
#else #else
#include "chrome/browser/chrome_browser_field_trials_desktop.h" #include "chrome/browser/chrome_browser_field_trials_desktop.h"
#endif #endif
...@@ -111,6 +112,27 @@ void ChromeBrowserFieldTrials::RegisterSyntheticTrials() { ...@@ -111,6 +112,27 @@ void ChromeBrowserFieldTrials::RegisterSyntheticTrials() {
ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial( ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
kReachedCodeProfilerTrial, reached_code_profiler_group); kReachedCodeProfilerTrial, reached_code_profiler_group);
} }
const char* group_name;
bool java_feature_enabled =
chrome::android::IsJavaDrivenFeatureEnabled(features::kEarlyLibraryLoad);
bool feature_enabled =
base::FeatureList::IsEnabled(features::kEarlyLibraryLoad);
// Use the default group if cc and java feature values don't agree (can happen
// on first startup after feature is enabled by Finch), or the feature is not
// overridden by Finch.
if (feature_enabled != java_feature_enabled ||
!base::FeatureList::GetInstance()->IsFeatureOverridden(
features::kEarlyLibraryLoad.name)) {
group_name = "Default";
} else if (java_feature_enabled) {
group_name = "Enabled";
} else {
group_name = "Disabled";
}
static constexpr char kEarlyLibraryLoadTrial[] = "EarlyLibraryLoadSynthetic";
ChromeMetricsServiceAccessor::RegisterSyntheticFieldTrial(
kEarlyLibraryLoadTrial, group_name);
#endif // defined(OS_ANDROID) #endif // defined(OS_ANDROID)
} }
......
...@@ -88,6 +88,7 @@ const base::Feature* kFeaturesExposedToJava[] = { ...@@ -88,6 +88,7 @@ const base::Feature* kFeaturesExposedToJava[] = {
&embedder_support::kShowTrustedPublisherURL, &embedder_support::kShowTrustedPublisherURL,
&features::kClearOldBrowsingData, &features::kClearOldBrowsingData,
&features::kDownloadsLocationChange, &features::kDownloadsLocationChange,
&features::kEarlyLibraryLoad,
&features::kGenericSensorExtraClasses, &features::kGenericSensorExtraClasses,
&features::kInstallableAmbientBadgeInfoBar, &features::kInstallableAmbientBadgeInfoBar,
&features::kMetricsSettingsAndroid, &features::kMetricsSettingsAndroid,
......
...@@ -56,6 +56,7 @@ public class CachedFeatureFlags { ...@@ -56,6 +56,7 @@ public class CachedFeatureFlags {
put(ChromeFeatureList.SERVICE_MANAGER_FOR_BACKGROUND_PREFETCH, true); put(ChromeFeatureList.SERVICE_MANAGER_FOR_BACKGROUND_PREFETCH, true);
put(ChromeFeatureList.COMMAND_LINE_ON_NON_ROOTED, false); put(ChromeFeatureList.COMMAND_LINE_ON_NON_ROOTED, false);
put(ChromeFeatureList.DOWNLOADS_AUTO_RESUMPTION_NATIVE, true); put(ChromeFeatureList.DOWNLOADS_AUTO_RESUMPTION_NATIVE, true);
put(ChromeFeatureList.EARLY_LIBRARY_LOAD, false);
put(ChromeFeatureList.PRIORITIZE_BOOTSTRAP_TASKS, true); put(ChromeFeatureList.PRIORITIZE_BOOTSTRAP_TASKS, true);
put(ChromeFeatureList.IMMERSIVE_UI_MODE, false); put(ChromeFeatureList.IMMERSIVE_UI_MODE, false);
put(ChromeFeatureList.SHARE_BY_DEFAULT_IN_CCT, false); put(ChromeFeatureList.SHARE_BY_DEFAULT_IN_CCT, false);
......
...@@ -292,6 +292,7 @@ public abstract class ChromeFeatureList { ...@@ -292,6 +292,7 @@ public abstract class ChromeFeatureList {
public static final String DOWNLOADS_LOCATION_CHANGE = "DownloadsLocationChange"; public static final String DOWNLOADS_LOCATION_CHANGE = "DownloadsLocationChange";
public static final String DOWNLOAD_LATER = "DownloadLater"; public static final String DOWNLOAD_LATER = "DownloadLater";
public static final String EDIT_PASSWORDS_IN_SETTINGS = "EditPasswordsInSettings"; public static final String EDIT_PASSWORDS_IN_SETTINGS = "EditPasswordsInSettings";
public static final String EARLY_LIBRARY_LOAD = "EarlyLibraryLoad";
public static final String ENHANCED_PROTECTION_PROMO_CARD = "EnhancedProtectionPromoCard"; public static final String ENHANCED_PROTECTION_PROMO_CARD = "EnhancedProtectionPromoCard";
public static final String EPHEMERAL_TAB_USING_BOTTOM_SHEET = "EphemeralTabUsingBottomSheet"; public static final String EPHEMERAL_TAB_USING_BOTTOM_SHEET = "EphemeralTabUsingBottomSheet";
public static final String EXPLICIT_LANGUAGE_ASK = "ExplicitLanguageAsk"; public static final String EXPLICIT_LANGUAGE_ASK = "ExplicitLanguageAsk";
......
...@@ -332,6 +332,12 @@ const base::Feature kDownloadsLocationChange{"DownloadsLocationChange", ...@@ -332,6 +332,12 @@ const base::Feature kDownloadsLocationChange{"DownloadsLocationChange",
base::FEATURE_ENABLED_BY_DEFAULT}; base::FEATURE_ENABLED_BY_DEFAULT};
#endif #endif
#if defined(OS_ANDROID)
// Enable loading native libraries earlier in startup on Android.
const base::Feature kEarlyLibraryLoad{"EarlyLibraryLoad",
base::FEATURE_DISABLED_BY_DEFAULT};
#endif
// Enables all registered system web apps, regardless of their respective // Enables all registered system web apps, regardless of their respective
// feature flags. // feature flags.
const base::Feature kEnableAllSystemWebApps{"EnableAllSystemWebApps", const base::Feature kEnableAllSystemWebApps{"EnableAllSystemWebApps",
......
...@@ -213,6 +213,11 @@ COMPONENT_EXPORT(CHROME_FEATURES) ...@@ -213,6 +213,11 @@ COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kDownloadsLocationChange; extern const base::Feature kDownloadsLocationChange;
#endif #endif
#if defined(OS_ANDROID)
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kEarlyLibraryLoad;
#endif
COMPONENT_EXPORT(CHROME_FEATURES) COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kEnableAllSystemWebApps; extern const base::Feature kEnableAllSystemWebApps;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment