Bug 1341097 - Part 4: Misc. small optimizations. r=mak, a=lizzard
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 20 Feb 2017 16:06:27 +0000
changeset 378915 d7d8bd983a300b3fa9a15be16b698c62e48f4b2b
parent 378914 c4ed29d7cddeb8129ec1c8ce7982f78d95cdf36e
child 378916 a94edff8355a1c83ad2bfad80d48540a3cfdfcf6
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak, lizzard
bugs1341097
milestone53.0a2
Bug 1341097 - Part 4: Misc. small optimizations. r=mak, a=lizzard The MigrationUtils change is because 99% of the time we will only have 1 visit per URI, and so we spend silly amounts of time doing nothing. Time spent in composing our undo structure went from ~800ms to ~550ms with this change. The other change just seemed obvious - when visits aren't recent, we shouldn't add them to 'recently visited' lists, which seem to use 'time this function was called' as the time associated with an entry, which is incorrect. MozReview-Commit-ID: 2I0D5ApOCI7
browser/components/migration/MigrationUtils.jsm
toolkit/components/places/History.cpp
--- a/browser/components/migration/MigrationUtils.jsm
+++ b/browser/components/migration/MigrationUtils.jsm
@@ -1049,18 +1049,24 @@ this.MigrationUtils = Object.freeze({
     return this._postProcessUndoData(undoData);
   },
 
   _updateHistoryUndo(places) {
     let visits = gUndoData.get("visits");
     let visitMap = new Map(visits.map(v => [v.url, v]));
     for (let place of places) {
       let visitCount = place.visits.length;
-      let first = Math.min.apply(Math, place.visits.map(v => v.visitDate));
-      let last = Math.max.apply(Math, place.visits.map(v => v.visitDate));
+      let first, last;
+      if (visitCount > 1) {
+        let visitDates = place.visits.map(v => v.visitDate);
+        first = Math.min.apply(Math, visitDates);
+        last = Math.max.apply(Math, visitDates);
+      } else {
+        first = last = place.visits[0].visitDate;
+      }
       let url = place.uri.spec;
       try {
         new URL(url);
       } catch (ex) {
         // This won't save and we won't need to 'undo' it, so ignore this URL.
         continue;
       }
       if (!visitMap.has(url)) {
--- a/toolkit/components/places/History.cpp
+++ b/toolkit/components/places/History.cpp
@@ -667,17 +667,19 @@ public:
     if (obsService) {
       DebugOnly<nsresult> rv =
         obsService->NotifyObservers(uri, URI_VISIT_SAVED, nullptr);
       NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "Could not notify observers");
     }
 
     History* history = History::GetService();
     NS_ENSURE_STATE(history);
-    history->AppendToRecentlyVisitedURIs(uri);
+    if (PR_Now() - mPlace.visitTime < RECENTLY_VISITED_URIS_MAX_AGE) {
+      mHistory->AppendToRecentlyVisitedURIs(uri);
+    }
     history->NotifyVisited(uri);
 
     return NS_OK;
   }
 private:
   VisitData mPlace;
   RefPtr<History> mHistory;
 };