From 3da8ca16f4f62489b593ae5849109c827f36ebff Mon Sep 17 00:00:00 2001 From: Lee Shombert Date: Thu, 13 Aug 2020 19:32:18 -0700 Subject: [PATCH] Reduce auto-cork delay to 50ms Bug: 160971853 Reduce the auto-cork delay from 2s to 50ms. Testing shows that this introduces a very few new invalidate calls for the package_info cache key, and greatly improves the hit ratio for the associated caches. This change includes a fix to the cache-clear counter. Some clears were missing. Test: * phone reboot * atest CtsContactsProviderTestCases * atest FrameworksServicesTests:UserSystemPackageInstallerTest * atest FrameworksServicesTests:PackageManagerSettingsTests Verified that hit ratios improved over the baseline. Verified that the number of extra invalidates did not increase by more than 5. Change-Id: I4b70b1da8c3927c74077e6da0e60dc56c2e007f1 --- core/java/android/app/PropertyInvalidatedCache.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/PropertyInvalidatedCache.java b/core/java/android/app/PropertyInvalidatedCache.java index 54f3f10260501..6c6c04e4e9752 100644 --- a/core/java/android/app/PropertyInvalidatedCache.java +++ b/core/java/android/app/PropertyInvalidatedCache.java @@ -413,7 +413,7 @@ public abstract class PropertyInvalidatedCache { public final void disableLocal() { synchronized (mLock) { mDisabled = true; - mCache.clear(); + clear(); } } @@ -463,7 +463,7 @@ public abstract class PropertyInvalidatedCache { cacheName(), mCache.size(), mLastSeenNonce, currentNonce)); } - mCache.clear(); + clear(); mLastSeenNonce = currentNonce; cachedResult = null; } @@ -728,9 +728,13 @@ public abstract class PropertyInvalidatedCache { * It's better to use explicit cork and uncork pairs that tighly surround big batches of * invalidations, but it's not always practical to tell where these invalidation batches * might occur. AutoCorker's time-based corking is a decent alternative. + * + * The auto-cork delay is configurable but it should not be too long. The purpose of + * the delay is to minimize the number of times a server writes to the system property + * when invalidating the cache. One write every 50ms does not hurt system performance. */ public static final class AutoCorker { - public static final int DEFAULT_AUTO_CORK_DELAY_MS = 2000; + public static final int DEFAULT_AUTO_CORK_DELAY_MS = 50; private final String mPropertyName; private final int mAutoCorkDelayMs;