Commit d04b58c0 authored by Clark DuVall's avatar Clark DuVall Committed by Chromium LUCI CQ

Avoid performing Android OMR1 dex compile workaround on local builds

The workaround causes perf regressions on the bots because it is
compiling the dex in the background. This is expected, so ignore the
workaround on local builds.

This also pushes compiling the dex to after startup in a best effort
task, to hopefully not compete with any crucial startup tasks and avoid
wiping any compiled dex before loading the chrome split.

Bug: 1160025, 1160029, 1159608
Change-Id: I704a3c3027ac13b7dc461a18bcc4e18f6e99c62d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2597890
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Auto-Submit: Clark DuVall <cduvall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838505}
parent 1574c9e8
...@@ -2196,6 +2196,7 @@ android_library("base_module_java") { ...@@ -2196,6 +2196,7 @@ android_library("base_module_java") {
"//chrome/browser/flags:java", "//chrome/browser/flags:java",
"//chrome/browser/preferences:java", "//chrome/browser/preferences:java",
"//chrome/browser/util:java", "//chrome/browser/util:java",
"//chrome/browser/version:java",
"//components/crash/android:java", "//components/crash/android:java",
"//components/embedder_support/android:application_java", "//components/embedder_support/android:application_java",
"//components/media_router/browser/android:cast_options_provider_java", "//components/media_router/browser/android:cast_options_provider_java",
......
...@@ -25,8 +25,12 @@ import org.chromium.base.PackageUtils; ...@@ -25,8 +25,12 @@ import org.chromium.base.PackageUtils;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
import org.chromium.base.compat.ApiHelperForO; import org.chromium.base.compat.ApiHelperForO;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.task.PostTask;
import org.chromium.base.task.TaskTraits;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys; import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager; import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.version.ChromeVersionInfo;
import org.chromium.content_public.browser.BrowserStartupController;
import java.lang.reflect.Field; import java.lang.reflect.Field;
...@@ -182,38 +186,59 @@ public class SplitChromeApplication extends SplitCompatApplication { ...@@ -182,38 +186,59 @@ public class SplitChromeApplication extends SplitCompatApplication {
* compile if necessary. * compile if necessary.
*/ */
private void applyDexCompileWorkaround() { private void applyDexCompileWorkaround() {
// This bug only happens in OMR1. // This bug only happens in OMR1. Skip the workaround on local builds to avoid affecting
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O_MR1) { // perf bots.
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.O_MR1
|| ChromeVersionInfo.isLocalBuild()) {
return; return;
} }
new Thread(() -> { // Wait until startup completes so this doesn't slow down early startup or mess with
try { // compiled dex files before they get loaded initially.
// If the app has just been updated, it will be compiled with quicken. The next time // TODO(crbug.com/1159608): Determine if this works good enough, or if more needs to be done
// bg-dexopt-job runs it will break the optimized dex for splits. If we force // to avoid slowing startup.
// compile now, then bg-dexopt-job won't mess up the splits, and we save the user a BrowserStartupController.getInstance().addStartupCompletedObserver(
// slow startup. new BrowserStartupController.StartupCallback() {
if (needsDexCompileAfterUpdate()) { @Override
performDexCompile(); public void onSuccess() {
return; // BEST_EFFORT will only affect when the task runs, the dexopt will run with
} // normal priority (but in a separate process, due to using Runtime.exec()).
PostTask.postTask(TaskTraits.BEST_EFFORT_MAY_BLOCK, () -> {
try {
// If the app has just been updated, it will be compiled with
// quicken. The next time bg-dexopt-job runs it will break the
// optimized dex for splits. If we force compile now, then
// bg-dexopt-job won't mess up the splits, and we save the user a
// slow startup.
if (needsDexCompileAfterUpdate()) {
performDexCompile();
return;
}
// Make sure all splits are compiled correclty, and if not force a compile. // Make sure all splits are compiled correclty, and if not force a
String[] splitNames = ApiHelperForO.getSplitNames(getApplicationInfo()); // compile.
for (int i = 0; i < splitNames.length; i++) { String[] splitNames =
// Ignore config splits like "config.en". ApiHelperForO.getSplitNames(getApplicationInfo());
if (splitNames[i].contains(".")) { for (int i = 0; i < splitNames.length; i++) {
continue; // Ignore config splits like "config.en".
if (splitNames[i].contains(".")) {
continue;
}
if (DexFile.isDexOptNeeded(
getApplicationInfo().splitSourceDirs[i])) {
performDexCompile();
return;
}
}
} catch (Exception e) {
Log.e(TAG, "Error compiling dex.", e);
}
});
} }
if (DexFile.isDexOptNeeded(getApplicationInfo().splitSourceDirs[i])) {
performDexCompile(); @Override
return; public void onFailure() {}
} });
}
} catch (Exception e) {
Log.e(TAG, "Error compiling dex.", e);
}
}).start();
} }
/** Returns whether the dex has been compiled since the last app update. */ /** Returns whether the dex has been compiled since the last app update. */
......
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