From 5de13ebb49c338206708b4ee82f396b0d2b75117 Mon Sep 17 00:00:00 2001 From: Mark Hammond Date: Wed, 26 Aug 2015 10:43:07 +1000 Subject: [PATCH] Bug 1186714 - bookmark backup yields the event loop occasionally to reduce jank. r=mak --- toolkit/components/places/PlacesUtils.jsm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/toolkit/components/places/PlacesUtils.jsm b/toolkit/components/places/PlacesUtils.jsm index 17e3bb199002..b60f68e8ceb8 100644 --- a/toolkit/components/places/PlacesUtils.jsm +++ b/toolkit/components/places/PlacesUtils.jsm @@ -1921,6 +1921,7 @@ this.PlacesUtils = { { tags_folder: PlacesUtils.tagsFolderId, charset_anno: PlacesUtils.CHARSET_ANNO, item_guid: aItemGuid }); + let yieldCounter = 0; for (let row of rows) { let item; if (!rootItem) { @@ -1959,6 +1960,14 @@ this.PlacesUtils = { if (item.type == this.TYPE_X_MOZ_PLACE_CONTAINER) parentsMap.set(item.guid, item); + + // With many bookmarks we end up stealing the CPU - even with yielding! + // So we let everyone else have a go every few items (bug 1186714). + if (++yieldCounter % 50 == 0) { + yield new Promise(resolve => { + Services.tm.currentThread.dispatch(resolve, Ci.nsIThread.DISPATCH_NORMAL); + }); + } } return rootItem;