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
--- 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;
};