Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: lib/prefs.js

Issue 29555660: Issue 5769 - Worked around bad Firefox 55 storage performance (Closed) Base URL: https://hg.adblockplus.org/adblockpluschrome
Patch Set: Created Sept. 25, 2017, 10:38 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/prefs.js
===================================================================
--- a/lib/prefs.js
+++ b/lib/prefs.js
@@ -233,16 +233,53 @@ function keyToPref(key)
return key.substr(keyPrefix.length);
}
function prefToKey(pref)
{
return keyPrefix + pref;
}
+function savePref(pref)
+{
+ ext.storage.set(prefToKey(pref), overrides[pref]);
+}
+
+let customSave = new Map();
+if (require("info").platform == "gecko")
+{
+ // Saving one storage value causes all others to be saved as well on Gecko.
+ // Make sure that updating ad counter doesn't cause the filters data to be
+ // saved frequently as a side-effect.
+ const MIN_UPDATE_INTERVAL = 60 * 1000;
+ let lastUpdate = -MIN_UPDATE_INTERVAL;
+ let updateScheduled = false;
+ customSave.set("blocked_total", pref =>
+ {
+ if (updateScheduled)
+ return;
+
+ let callback = () =>
+ {
+ lastUpdate = performance.now();
+ updateScheduled = false;
+ savePref(pref);
+ };
+
+ let timeElapsed = performance.now() - lastUpdate;
+ if (timeElapsed < MIN_UPDATE_INTERVAL)
+ {
+ setTimeout(callback, MIN_UPDATE_INTERVAL - timeElapsed);
+ updateScheduled = true;
+ }
+ else
+ callback();
+ });
+}
+
function addPreference(pref)
{
Object.defineProperty(Prefs, pref, {
get() { return (pref in overrides ? overrides : defaults)[pref]; },
set(value)
{
let defaultValue = defaults[pref];
@@ -252,17 +289,17 @@ function addPreference(pref)
if (value == defaultValue)
{
delete overrides[pref];
ext.storage.remove(prefToKey(pref));
}
else
{
overrides[pref] = value;
- ext.storage.set(prefToKey(pref), value);
+ (customSave.get(pref) || savePref)(pref);
}
},
enumerable: true
});
}
function init()
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld