Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e574a37d authored by Winson Chiu's avatar Winson Chiu
Browse files

Fix high traffic PMS lockless methods

The notifyPackageUse method is called so many times that it is
causing a spike in snapshot invalidations. This reverts to a
(broken) S state where the code takes the lock and updates
the time value, but doesn't actually invalidate the snapshot,
preventing the re-generation.

Also fixes a check in grantImplicitAccess that was calling
onChanged() even though nothing changed, which was the other
significant method.

Test: manual, run profiling steps in bug on pre-change and post-change
Test: atest AppsFilterImplTest

Bug: 236021119

Change-Id: I20b1bb1d8b4f3df09c901f39db8462ab1a67607d
parent 565f6d45
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -418,7 +418,9 @@ public final class AppsFilterImpl extends AppsFilterLocked implements Watchable,
        } else if (changed) {
        } else if (changed) {
            invalidateCache("grantImplicitAccess: " + recipientUid + " -> " + visibleUid);
            invalidateCache("grantImplicitAccess: " + recipientUid + " -> " + visibleUid);
        }
        }
        if (changed) {
            onChanged();
            onChanged();
        }
        return changed;
        return changed;
    }
    }


+7 −4
Original line number Original line Diff line number Diff line
@@ -2859,12 +2859,15 @@ public class PackageManagerService implements PackageSender, TestUtilityService
        mDexOptHelper.performPackageDexOptUpgradeIfNeeded();
        mDexOptHelper.performPackageDexOptUpgradeIfNeeded();
    }
    }



    private void notifyPackageUseInternal(String packageName, int reason) {
    private void notifyPackageUseInternal(String packageName, int reason) {
        long time = System.currentTimeMillis();
        long time = System.currentTimeMillis();
        commitPackageStateMutation(null, packageName, packageState -> {
        synchronized (mLock) {
            packageState.setLastPackageUsageTime(reason, time);
            final PackageSetting pkgSetting = mSettings.getPackageLPr(packageName);
        });
            if (pkgSetting == null) {
                return;
            }
            pkgSetting.getPkgState().setLastPackageUsageTimeInMills(reason, time);
        }
    }
    }


    /*package*/ DexManager getDexManager() {
    /*package*/ DexManager getDexManager() {
+4 −1
Original line number Original line Diff line number Diff line
@@ -79,7 +79,10 @@ public class PackageStateUnserialized {
            return this;
            return this;
        }
        }
        getLastPackageUsageTimeInMills()[reason] = time;
        getLastPackageUsageTimeInMills()[reason] = time;
        mPackageSetting.onChanged();
        // TODO(b/236180425): This method does not notify snapshot changes because it's called too
        //  frequently, causing too many re-takes. This should be moved to a separate data structure
        //  or merged with the general UsageStats to avoid tracking heavily mutated data in the
        //  package data snapshot.
        return this;
        return this;
    }
    }