From 4435606858811bd07a4ccd3e218d175501f2b615 Mon Sep 17 00:00:00 2001 From: Tobias Thierer Date: Fri, 4 Oct 2019 00:31:59 +0100 Subject: Construct default MimeMap lazily rather than eagerly. A side effect of CL topic r.android.com/q/topic:bug136256059_attempt2 was that the default MimeMap instance is now loaded eagerly (pre-fork) regardless of whether any app process ends up using it, whereas previously it was loaded lazily (post-fork) the first time an app process used it. This traded off CPU and memory use post-fork vs. pre-fork. Because it isn't known / hasn't been proven whether and how many app processes use that instance, the net CPU and memory impact is not known: if at least one process makes use of a relevant API, the net impact will be neutral or positive, or else negative. Until this can be investigated and undergo system health review, this CL topic changes the behavior back to post-fork lazy loading of the default MimeMap instance. Bug: 142019040 Test: Treehugger Change-Id: I2a3f244240c51e7ada1f41a8abadb946ebcab40b --- core/java/com/android/internal/os/RuntimeInit.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/java/com/android/internal/os/RuntimeInit.java b/core/java/com/android/internal/os/RuntimeInit.java index 103c79d22530..fd3cd42b07a1 100644 --- a/core/java/com/android/internal/os/RuntimeInit.java +++ b/core/java/com/android/internal/os/RuntimeInit.java @@ -203,13 +203,15 @@ public class RuntimeInit { public static void preForkInit() { if (DEBUG) Slog.d(TAG, "Entered preForkInit."); RuntimeInit.enableDdms(); + // TODO(b/142019040#comment13): Decide whether to load the default instance eagerly, i.e. + // MimeMap.setDefault(DefaultMimeMapFactory.create()); /* * Replace libcore's minimal default mapping between MIME types and file * extensions with a mapping that's suitable for Android. Android's mapping * contains many more entries that are derived from IANA registrations but * with several customizations (extensions, overrides). */ - MimeMap.setDefault(DefaultMimeMapFactory.create()); + MimeMap.setDefaultSupplier(DefaultMimeMapFactory::create); } @UnsupportedAppUsage -- cgit v1.2.3-59-g8ed1b