Bug 1341097 - part 4: misc. small optimizations, r?mak draft
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 20 Feb 2017 16:06:27 +0000
changeset 490134 55142c144c499b8dafc330eb4696d45a5d769f08
parent 490133 b4416a2024e280ceba38dbb4dcae8357c653a6a6
child 547177 ebd4f358b4d0117d762b35ddfb623e990f6e0350
push id47007
push usergijskruitbosch@gmail.com
push dateMon, 27 Feb 2017 18:10:34 +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;
 };