Bug 1369604: Force lazily-loaded metadata to load on background thread. r=liuche
☠☠ backed out by f91ecef40cab ☠ ☠
authorMichael Comella <michael.l.comella@gmail.com>
Fri, 28 Jul 2017 15:02:57 -0700
changeset 422895 e49ad83bc31b4f1d14a0d0319822d65c30acaedf
parent 422894 b33806ccdd9fbe51e11744cb3f44b807a102e29c
child 422896 10a40b857266d63cf5c0577fd163d896b9c35eca
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersliuche
bugs1369604
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1369604: Force lazily-loaded metadata to load on background thread. r=liuche This undoes a caveat created from the last changeset; I did not profile this change. MozReview-Commit-ID: 6jpXyt0GRUj
mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/HighlightsLoader.java
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/HighlightsLoader.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/HighlightsLoader.java
@@ -4,23 +4,25 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.activitystream.homepanel;
 
 import android.content.Context;
 import android.database.ContentObserver;
 import android.database.Cursor;
 import android.os.SystemClock;
+import android.support.annotation.WorkerThread;
 import android.support.v4.content.AsyncTaskLoader;
 
 import org.mozilla.gecko.Telemetry;
 import org.mozilla.gecko.activitystream.ranking.HighlightsRanking;
 import org.mozilla.gecko.db.BrowserContract;
 import org.mozilla.gecko.db.BrowserDB;
 import org.mozilla.gecko.activitystream.homepanel.model.Highlight;
+import org.mozilla.gecko.util.ThreadUtils;
 
 import java.util.Collections;
 import java.util.List;
 
 /**
  * Loader implementation for loading a list of ranked highlights from the database.
  */
 /* package-private */ class HighlightsLoader extends AsyncTaskLoader<List<Highlight>> {
@@ -57,25 +59,38 @@ import java.util.List;
             return Collections.emptyList();
         }
 
         try {
             // From now on get notified about content updates and reload data - until loader is reset.
             enableContentUpdates();
 
             final List<Highlight> highlights = HighlightsRanking.rank(candidatesCursor, highlightsLimit);
+            forceLoadHighlightMetadata(highlights); // force load now that we have a short list of the data.
 
             addToPerformanceHistogram(startTime);
 
             return highlights;
         } finally {
             candidatesCursor.close();
         }
     }
 
+    /**
+     * Optimization: we force the lazily-loaded metadata to load while we're running on this background thread
+     * rather than letting it block the UI thread when this data is being used in the UI.
+     */
+    @WorkerThread
+    private static void forceLoadHighlightMetadata(final List<Highlight> highlights) {
+        ThreadUtils.assertNotOnUiThread();
+        for (final Highlight highlight : highlights) {
+            highlight.getMetadataSlow();
+        }
+    }
+
     private void addToPerformanceHistogram(long startTime) {
         final long took = SystemClock.uptimeMillis() - startTime;
 
         Telemetry.addToHistogram(TELEMETRY_HISTOGRAM_ACTIVITY_STREAM_HIGHLIGHTS, (int) Math.min(took, Integer.MAX_VALUE));
     }
 
     @Override
     protected void onReset() {