From 0d917af02ba7a7b24719c3cc6d41c740640ce6d3 Mon Sep 17 00:00:00 2001 From: Songchun Fan Date: Wed, 4 May 2022 00:49:27 +0000 Subject: [PATCH] [snapshot] use caches for arraylists in mAppIds BUG: 231373522 Test: forrest run shows a small improvement on boot time Before: TOTAL_BOOT_TIME-mean:18003.20 After: TOTAL_BOOT_TIME-mean:17976.80 Change-Id: I05d5d6b10d29b82906165c459f2ff6504e8ef95d --- .../android/server/pm/AppIdSettingMap.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/pm/AppIdSettingMap.java b/services/core/java/com/android/server/pm/AppIdSettingMap.java index b41a0b8878e0a..20c67f87d3b9b 100644 --- a/services/core/java/com/android/server/pm/AppIdSettingMap.java +++ b/services/core/java/com/android/server/pm/AppIdSettingMap.java @@ -19,6 +19,7 @@ package com.android.server.pm; import android.os.Process; import android.util.Log; +import com.android.server.utils.SnapshotCache; import com.android.server.utils.WatchedArrayList; import com.android.server.utils.WatchedSparseArray; import com.android.server.utils.Watcher; @@ -34,10 +35,28 @@ final class AppIdSettingMap { * index to the corresponding SettingBase object is (appId - FIRST_APPLICATION_ID). If an app ID * doesn't exist (i.e., app is not installed), we fill the corresponding entry with null. */ - private WatchedArrayList mNonSystemSettings = new WatchedArrayList<>(); - private WatchedSparseArray mSystemSettings = new WatchedSparseArray<>(); + private final WatchedArrayList mNonSystemSettings; + private final SnapshotCache> mNonSystemSettingsSnapshot; + private final WatchedSparseArray mSystemSettings; + private final SnapshotCache> mSystemSettingsSnapshot; private int mFirstAvailableAppId = Process.FIRST_APPLICATION_UID; + AppIdSettingMap() { + mNonSystemSettings = new WatchedArrayList<>(); + mNonSystemSettingsSnapshot = new SnapshotCache.Auto<>( + mNonSystemSettings, mNonSystemSettings, "AppIdSettingMap.mNonSystemSettings"); + mSystemSettings = new WatchedSparseArray<>(); + mSystemSettingsSnapshot = new SnapshotCache.Auto<>( + mSystemSettings, mSystemSettings, "AppIdSettingMap.mSystemSettings"); + } + + AppIdSettingMap(AppIdSettingMap orig) { + mNonSystemSettings = orig.mNonSystemSettingsSnapshot.snapshot(); + mNonSystemSettingsSnapshot = new SnapshotCache.Sealed<>(); + mSystemSettings = orig.mSystemSettingsSnapshot.snapshot(); + mSystemSettingsSnapshot = new SnapshotCache.Sealed<>(); + } + /** Returns true if the requested AppID was valid and not already registered. */ public boolean registerExistingAppId(int appId, SettingBase setting, Object name) { if (appId >= Process.FIRST_APPLICATION_UID) { @@ -134,10 +153,7 @@ final class AppIdSettingMap { } public AppIdSettingMap snapshot() { - AppIdSettingMap l = new AppIdSettingMap(); - mNonSystemSettings.snapshot(l.mNonSystemSettings, mNonSystemSettings); - mSystemSettings.snapshot(l.mSystemSettings, mSystemSettings); - return l; + return new AppIdSettingMap(this); } public void registerObserver(Watcher observer) {