From 7bd7a369e4e483170fa118d17df9b36ff5ecac5f Mon Sep 17 00:00:00 2001 From: Richard Uhler Date: Mon, 21 May 2018 10:37:24 +0100 Subject: [PATCH] Reduce LoadedApkAssets LRU cache size. The cached apk assets can take up multiple megabytes of .apk mmap and native memory for associated data structures. Reduce the cache size for potential multi-megabyte memory savings with hopefully no noticeable performance impacts. In particular, rough estimates of the memory and performance impacts of this change were evaluated by starting the launcher app, sampling system server PSS with dumpsys meminfo and cache stats using dumpsys activity for a few different cache sizes: LRU Size 1: cached apks: total= 1 created=0 evicted=33 hit= 0 miss=34 max=1 TOTAL PSS=187542 LRU Size 3: cached apks: total= 3 created=0 evicted=12 hit=19 miss=15 max=3 TOTAL PSS=190606 LRU Size 15: cached apks: total=15 created=0 evicted= 0 hit=19 miss=15 max=15 TOTAL PSS=199350 LRU Size 100: cached apks: total=15 created=0 evicted= 0 hit=19 miss=15 max=100 TOTAL PSS=201416 Comparing cache stats after launching the settings app: LRU Size 3: cached apks: total=3 created=0 evicted=5 hit=14 miss=8 max=3 LRU Size 15: cached apks: total=6 created=0 evicted=0 hit=18 miss=6 max=15 Running performance tests locally to ensure no clear regression in app startup: app-startup/benchmark-app-hermetic/cold-dropcache-test: LRU 15 3 3 activityStart: 40.47 38.53 39.27 bindApplication: 24.40 24.53 24.93 draw: 4.27 4.33 4.07 layout: 0.73 1.07 0.73 onCreate: 9.40 9.00 8.53 totalLaunchTime: 183.13 183.27 187.07 app-startup/hermetic-apps/cold-dropcache-test: LRU 15 15 3 3 Calculator_avg: 333.9 333.1 343.3 334.6 Calculator_max: 345.0 360.0 370.0 363.0 Calculator_median: 333.5 331.5 343.5 333.5 Calculator_min: 320.0 317.0 320.0 311.0 Calculator_std_dev: 6.62 13.26 18.22 16.51 Clock_avg: 510.0 511.2 509.2 512.6 Clock_max: 529.0 528.0 530.0 529.0 Clock_median: 510.5 509.0 503.5 512.0 Clock_min: 498.0 495.0 487.0 492.0 Clock_std_dev: 7.70 11.71 15.25 11.07 Contacts_avg: 457.7 527.3 507.3 543.9 Contacts_max: 602.0 622.0 591.0 588.0 Contacts_median: 410.5 568.5 568.0 580.0 Contacts_min: 390.0 374.0 366.0 394.0 Contacts_std_dev: 85.64 96.80 88.80 72.97 Phone_avg: 6073.1 6109.7 6110.8 6115.8 Phone_max: 6196.0 6208.0 6180.0 6222.0 Phone_median: 6070.0 6117.5 6100.0 6133.5 Phone_min: 5982.0 5990.0 6061.0 5994.0 Phone_std_dev: 61.49 67.35 34.55 60.17 Settings_avg: 457.9 446.6 451.6 428.7 Settings_max: 487.0 468.0 494.0 449.0 Settings_median: 460.0 450.0 444.5 424.0 Settings_min: 423.0 421.0 431.0 420.0 Settings_std_dev: 21.21 12.02 20.46 9.71 Bug: 79115008 Test: Device boots. Test: dumpsys activity all shows ResourcesManager max cache size of 3. Change-Id: I7225b6978fac6197c27bec23d2b477fb1f5aee43 --- core/java/android/app/ResourcesManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java index fc5ea6607d87b..30256b42e6a1d 100644 --- a/core/java/android/app/ResourcesManager.java +++ b/core/java/android/app/ResourcesManager.java @@ -124,7 +124,7 @@ public class ResourcesManager { /** * The ApkAssets we are caching and intend to hold strong references to. */ - private final LruCache mLoadedApkAssets = new LruCache<>(15); + private final LruCache mLoadedApkAssets = new LruCache<>(3); /** * The ApkAssets that are being referenced in the wild that we can reuse, even if they aren't