Bug 1580112 - Stop updating the database when the value has not changed. r=alwu

In most of the cases, the value to be stored is the same as the existing value, which does not require an update to the database. Setting something in the database requires disk access. By using this we avoid accessing the disk in the majority of the cases.

Differential Revision: https://phabricator.services.mozilla.com/D45504

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alex Chronopoulos 2019-09-11 20:21:51 +00:00
parent e613c24777
commit 966ab066dc

View File

@ -81,7 +81,11 @@ IPCResult BenchmarkStorageParent::RecvPut(const nsCString& aDbName,
}
MovingAverage(average, window, aValue);
int32_t newValue = PrepareStoredValue(average, window);
// Avoid storing if the values are the same. This is an optimization
// to minimize the disk usage.
if (aResult != newValue) {
storage->Put(aDbName, aKey, newValue);
}
},
[](nsresult rv) { /*do nothing*/ });