From bddae911fc3193a674e070e1c2be8016795c9fa4 Mon Sep 17 00:00:00 2001 From: James O'Leary Date: Mon, 8 Mar 2021 11:29:22 -0500 Subject: [PATCH] Fix boot time regression on Wembley After a ton of regression testing on Forrest and checking dashboards, turns out the boot time regression due to new color code only happens on Wembley in CI. Wembley in CI has 1 GB of RAM, or at least, it returns true for `ActivityManager.isLowRamDevice` To fix the regression, when we're performing clustering on a low RAM device, we'll use the prior clustering strategy (Kmeans, 5 colors). Net impact is speed improvement + there will be less options for colors. Kmeans erases less common colors first, and those colors tend to be good candidates for highly chromatic colors. Fixes: 181348302 Fixes: 181194430 Test: Did about 50 runs on Forrest, isolated issue. Final Forrest run showing that startservices_avg decreases to previous levels on Wembley with this CL is here: https://android-build.googleplex.com/builds/forrest/run/L87800000829799585 To see the improvement back to baseline (~1350 ms), open that link, at the table of the bottom of the page, click "asit/perf/boottime_test", then click Artifacts, then click test_results15031410639465275315_8163110686177237845.txt, and search for SystemUIBootTiming_startservices_avg. Alternatively, here is a direct link to the test results text file: https://android-build.googleplex.com/builds/I89400007809099518/git_master/P20404532/successiveboottest/inv_17043739560101466259/test_results15031410639465275315_8163110686177237845.txt Change-Id: I53ee5b5f95e6fd54f1327005e391d428f650dbfa --- core/java/android/app/WallpaperColors.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/core/java/android/app/WallpaperColors.java b/core/java/android/app/WallpaperColors.java index 0a8a73404a7b8..6b2e649b0c69f 100644 --- a/core/java/android/app/WallpaperColors.java +++ b/core/java/android/app/WallpaperColors.java @@ -32,6 +32,7 @@ import android.util.Size; import com.android.internal.graphics.ColorUtils; import com.android.internal.graphics.palette.CelebiQuantizer; import com.android.internal.graphics.palette.Palette; +import com.android.internal.graphics.palette.VariationalKMeansQuantizer; import com.android.internal.util.ContrastColorUtil; import java.io.FileOutputStream; @@ -178,11 +179,20 @@ public final class WallpaperColors implements Parcelable { optimalSize.getHeight(), true /* filter */); } - final Palette palette = Palette - .from(bitmap, new CelebiQuantizer()) - .maximumColorCount(256) - .resizeBitmapArea(MAX_WALLPAPER_EXTRACTION_AREA) - .generate(); + final Palette palette; + if (ActivityManager.isLowRamDeviceStatic()) { + palette = Palette + .from(bitmap, new VariationalKMeansQuantizer()) + .maximumColorCount(5) + .resizeBitmapArea(MAX_WALLPAPER_EXTRACTION_AREA) + .generate(); + } else { + palette = Palette + .from(bitmap, new CelebiQuantizer()) + .maximumColorCount(256) + .resizeBitmapArea(MAX_WALLPAPER_EXTRACTION_AREA) + .generate(); + } // Remove insignificant colors and sort swatches by population final ArrayList swatches = new ArrayList<>(palette.getSwatches()); swatches.sort((a, b) -> b.getPopulation() - a.getPopulation());