Bug 1341097 - part 4: misc. small optimizations, r?mak draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 20 Feb 2017 16:06:27 +0000
changeset 490137 c33645766cf34a63c02d3da0d4ef2c48e2a72b32
parent 490136 c38ad4696dabc9f675dec9fd1b6f1a7ee0c569e1
child 547179 c450b590449dc16405402ee6bf023ebb6c3ff093
push id47009
push usergijskruitbosch@gmail.com
push dateMon, 27 Feb 2017 18:28:07 +0000
reviewersmak
bugs1341097
milestone54.0a1
Bug 1341097 - part 4: misc. small optimizations, r?mak 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;
 };