summaryrefslogtreecommitdiff
path: root/core/java/android/app/ActivityThread.java
diff options
context:
space:
mode:
authorRiddle Hsu <riddlehsu@google.com>2019-04-12 17:37:10 +0800
committerRiddle Hsu <riddlehsu@google.com>2019-04-12 17:37:10 +0800
commit4e8e3b0204072a38026ce3955e77428e4dacb646 (patch)
tree351c635af32d46593525f7b29e50c1e280086cb2 /core/java/android/app/ActivityThread.java
parent4f1adafc680df3c8d85b5467f5fa9921b7197346 (diff)
Reduce transactions for acquiring and releasing provider
App may access a provider frequently in a short time. (Without using ContentProviderClient to keep the connection) Then there will have some overhead for the management of provider reference. So with a delay to release the provider, the app can reuse the existing holder within the retain time. Also change removeContentProvider to a one-way method to reduce the time spent on app's main thread. This should be safe because originally the app can acquire provider from any thread. The cold start time of calendar app can be reduced by ~20ms. Test: AppLaunchTest Bug: 123043091 Change-Id: I220cec3deab18b658f4102f7eb9f47599c7c4b7c
Diffstat (limited to 'core/java/android/app/ActivityThread.java')
-rw-r--r--core/java/android/app/ActivityThread.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index b6e5754aa65f..143361f721d1 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -224,6 +224,12 @@ public final class ActivityThread extends ClientTransactionHandler {
private static final boolean DEBUG_PROVIDER = false;
public static final boolean DEBUG_ORDER = false;
private static final long MIN_TIME_BETWEEN_GCS = 5*1000;
+ /**
+ * The delay to release the provider when it has no more references. It reduces the number of
+ * transactions for acquiring and releasing provider if the client accesses the provider
+ * frequently in a short time.
+ */
+ private static final long CONTENT_PROVIDER_RETAIN_TIME = 1000;
private static final int SQLITE_MEM_RELEASED_EVENT_LOG_TAG = 75003;
/** Type for IActivityManager.serviceDoneExecuting: anonymous operation */
@@ -6498,16 +6504,13 @@ public final class ActivityThread extends ClientTransactionHandler {
if (!prc.removePending) {
// Schedule the actual remove asynchronously, since we don't know the context
// this will be called in.
- // TODO: it would be nice to post a delayed message, so
- // if we come back and need the same provider quickly
- // we will still have it available.
if (DEBUG_PROVIDER) {
Slog.v(TAG, "releaseProvider: Enqueueing pending removal - "
+ prc.holder.info.name);
}
prc.removePending = true;
Message msg = mH.obtainMessage(H.REMOVE_PROVIDER, prc);
- mH.sendMessage(msg);
+ mH.sendMessageDelayed(msg, CONTENT_PROVIDER_RETAIN_TIME);
} else {
Slog.w(TAG, "Duplicate remove pending of provider " + prc.holder.info.name);
}