Commit 9c3efa77 authored by Dmitry Skiba's avatar Dmitry Skiba Committed by Commit Bot

Add a finch trial for disabling library prefetching.

We suspect that library prefetching slows startup on low-end devices.
This CL adds an experiment to verify that hypothesis.

Bug: 735799
Change-Id: I5bc969e7d417f07520caef28fc4e0598e545d51b
Reviewed-on: https://chromium-review.googlesource.com/578711
Commit-Queue: Dmitry Skiba <dskiba@chromium.org>
Reviewed-by: default avatarMaria Khomenko <mariakhomenko@chromium.org>
Reviewed-by: default avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488427}
parent 49d09440
......@@ -7,6 +7,7 @@ package org.chromium.base.library_loader;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.AsyncTask;
import android.os.StrictMode;
import android.os.SystemClock;
import org.chromium.base.CommandLine;
......@@ -48,6 +49,9 @@ public class LibraryLoader {
// Guards all access to the libraries
private static final Object sLock = new Object();
// SharedPreferences key for "don't prefetch libraries" flag
private static final String DONT_PREFETCH_LIBRARIES_KEY = "dont_prefetch_libraries";
// The singleton instance of NativeLibraryPreloader.
private static NativeLibraryPreloader sLibraryPreloader;
......@@ -193,6 +197,37 @@ public class LibraryLoader {
}
}
/**
* Disables prefetching for subsequent runs. The value comes from "DontPrefetchLibraries"
* finch experiment, and is pushed on every run. I.e. the effect of the finch experiment
* lags by one run, which is the best we can do considering that prefetching happens way
* before finch is initialized. Note that since LibraryLoader is in //base, it can't depend
* on ChromeFeatureList, and has to rely on external code pushing the value.
*
* @param dontPrefetch whether not to prefetch libraries
*/
public static void setDontPrefetchLibrariesOnNextRuns(boolean dontPrefetch) {
ContextUtils.getAppSharedPreferences()
.edit()
.putBoolean(DONT_PREFETCH_LIBRARIES_KEY, dontPrefetch)
.apply();
}
/**
* @return whether not to prefetch libraries (see setDontPrefetchLibrariesOnNextRun()).
*/
private static boolean isNotPrefetchingLibraries() {
// This might be the first time getAppSharedPreferences() is used, so relax strict mode
// to allow disk reads.
StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
try {
return ContextUtils.getAppSharedPreferences().getBoolean(
DONT_PREFETCH_LIBRARIES_KEY, false);
} finally {
StrictMode.setThreadPolicy(oldPolicy);
}
}
/** Prefetches the native libraries in a background thread.
*
* Launches an AsyncTask that, through a short-lived forked process, reads a
......@@ -203,6 +238,8 @@ public class LibraryLoader {
* detrimental to the startup time.
*/
public void asyncPrefetchLibrariesToMemory() {
if (isNotPrefetchingLibraries()) return;
final boolean coldStart = mPrefetchLibraryHasBeenCalled.compareAndSet(false, true);
new AsyncTask<Void, Void, Void>() {
@Override
......
......@@ -177,6 +177,7 @@ public abstract class ChromeFeatureList {
// Android.
public static final String DATA_REDUCTION_MAIN_MENU = "DataReductionProxyMainMenu";
public static final String DATA_REDUCTION_SITE_BREAKDOWN = "DataReductionProxySiteBreakdown";
public static final String DONT_PREFETCH_LIBRARIES = "DontPrefetchLibraries";
public static final String DOWNLOAD_HOME_SHOW_STORAGE_INFO = "DownloadHomeShowStorageInfo";
// When enabled, fullscreen WebContents will be moved to a new Activity. Coming soon...
public static final String FULLSCREEN_ACTIVITY = "FullscreenActivity";
......
......@@ -23,6 +23,7 @@ import org.chromium.base.FieldTrialList;
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.firstrun.FirstRunGlueImpl;
......@@ -188,6 +189,12 @@ public class FeatureUtilities {
cacheChromeHomeEnabled();
FirstRunGlueImpl.cacheFirstRunPrefs();
OmniboxPlaceholderFieldTrial.cacheOmniboxPlaceholderGroup();
// Propagate DONT_PREFETCH_LIBRARIES feature value to LibraryLoader. This can't
// be done in LibraryLoader itself because it lives in //base and can't depend
// on ChromeFeatureList.
LibraryLoader.setDontPrefetchLibrariesOnNextRuns(
ChromeFeatureList.isEnabled(ChromeFeatureList.DONT_PREFETCH_LIBRARIES));
}
/**
......
......@@ -3240,6 +3240,12 @@ const FeatureEntry kFeatureEntries[] = {
SINGLE_VALUE_TYPE(chromeos::switches::kEnableLockScreenApps)},
#endif // defined(OS_CHROMEOS)
#if defined(OS_ANDROID)
{"dont-prefetch-libraries", flag_descriptions::kDontPrefetchLibrariesName,
flag_descriptions::kDontPrefetchLibrariesDescription, kOsAndroid,
FEATURE_VALUE_TYPE(chrome::android::kDontPrefetchLibraries)},
#endif // defined(OS_ANDROID)
// NOTE: Adding new command-line switches requires adding corresponding
// entries to enum "LoginCustomFlags" in histograms/enums.xml. See note in
// enums.xml and don't forget to run AboutFlagsHistogramTest unit test.
......
......@@ -67,6 +67,7 @@ const base::Feature* kFeaturesExposedToJava[] = {
&kContextualSuggestionsCarousel,
&kCustomContextMenu,
&kCustomFeedbackUi,
&kDontPrefetchLibraries,
&kDownloadHomeShowStorageInfo,
&data_reduction_proxy::features::kDataReductionMainMenu,
&data_reduction_proxy::features::kDataReductionSiteBreakdown,
......@@ -179,6 +180,9 @@ const base::Feature kCustomContextMenu{"CustomContextMenu",
const base::Feature kCustomFeedbackUi{"CustomFeedbackUi",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kDontPrefetchLibraries{"DontPrefetchLibraries",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kDownloadAutoResumptionThrottling{
"DownloadAutoResumptionThrottling", base::FEATURE_ENABLED_BY_DEFAULT};
......
......@@ -32,6 +32,7 @@ extern const base::Feature kContextualSearchUrlActions;
extern const base::Feature kContextualSuggestionsCarousel;
extern const base::Feature kCustomContextMenu;
extern const base::Feature kCustomFeedbackUi;
extern const base::Feature kDontPrefetchLibraries;
extern const base::Feature kDownloadAutoResumptionThrottling;
extern const base::Feature kDownloadHomeShowStorageInfo;
extern const base::Feature kFullscreenActivity;
......
......@@ -1455,6 +1455,10 @@ const char kContextualSearchName[] = "Contextual Search";
const char kContextualSearchDescription[] =
"Whether or not Contextual Search is enabled.";
const char kDontPrefetchLibrariesName[] = "Don't Prefetch Libraries";
const char kDontPrefetchLibrariesDescription[] =
"Don't prefetch libraries after loading.";
const char kEnableAndroidPayIntegrationV1Name[] = "Enable Android Pay v1";
const char kEnableAndroidPayIntegrationV1Description[] =
"Enable integration with Android Pay using the first version of the API";
......
......@@ -902,6 +902,9 @@ extern const char kContextualSearchUrlActionsDescription[];
extern const char kContextualSearchName[];
extern const char kContextualSearchDescription[];
extern const char kDontPrefetchLibrariesName[];
extern const char kDontPrefetchLibrariesDescription[];
extern const char kEnableAndroidPayIntegrationV1Name[];
extern const char kEnableAndroidPayIntegrationV1Description[];
......
......@@ -22731,6 +22731,7 @@ uploading your change for review. These are checked by presubmit scripts.
<int value="-1578295753" label="UserMediaScreenCapturing:disabled"/>
<int value="-1575984706" label="gl-composited-overlay-candidate-quad-border"/>
<int value="-1575554415" label="AndroidPaymentAppsFilter:enabled"/>
<int value="-1575430234" label="DontPrefetchLibraries:disabled"/>
<int value="-1572010356" label="enable-privet-v3"/>
<int value="-1571841513" label="enable-devtools-experiments"/>
<int value="-1559789642" label="RunAllFlashInAllowMode:enabled"/>
......@@ -23351,6 +23352,7 @@ from previous Chrome versions.
<int value="575394365" label="AndroidPaymentApps:disabled"/>
<int value="581118445" label="enable-eol-notification"/>
<int value="581355159" label="ContentSuggestionsCategoryRanker:disabled"/>
<int value="582187448" label="DontPrefetchLibraries:enabled"/>
<int value="584541349" label="ContextualSearchSingleActions:disabled"/>
<int value="586021329" label="VibrateRequiresUserGesture:enabled"/>
<int value="592050831" label="disable-slimming-paint"/>
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