Bug 714964 - Add a 'dirty bit' column to webappsstore2_temp to reduces writes in DOM storage. r=honzab
authorVladan Djeric <vdjeric@mozilla.com>
Mon, 13 Feb 2012 14:18:38 -0500
changeset 86729 2986d2923fa92a0ef2de26f9797094ce22ceb757
parent 86728 f29587aa8965b19c0c6784c9d9eb41434fa50640
child 86730 862dec07105b34e7701b06dece9658bc1a019021
push id6005
push uservdjeric@mozilla.com
push dateMon, 13 Feb 2012 19:18:47 +0000
treeherdermozilla-inbound@2986d2923fa9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonzab
bugs714964
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 714964 - Add a 'dirty bit' column to webappsstore2_temp to reduces writes in DOM storage. r=honzab
dom/src/storage/nsDOMStoragePersistentDB.cpp
--- a/dom/src/storage/nsDOMStoragePersistentDB.cpp
+++ b/dom/src/storage/nsDOMStoragePersistentDB.cpp
@@ -183,30 +183,31 @@ nsDOMStoragePersistentDB::Init(const nsS
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = mConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
          "CREATE TEMPORARY TABLE webappsstore2_temp ("
          "scope TEXT, "
          "key TEXT, "
          "value TEXT, "
          "secure INTEGER, "
-         "owner TEXT)"));
+         "owner TEXT, "
+         "modified INTEGER DEFAULT 0)"));
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = mConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
         "CREATE UNIQUE INDEX scope_key_index_temp"
         " ON webappsstore2_temp(scope, key)"));
   NS_ENSURE_SUCCESS(rv, rv);
 
 
   rv = mConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
         "CREATE TEMPORARY VIEW webappsstore2_view AS "
-        "SELECT * FROM webappsstore2_temp "
+        "SELECT scope, key, value, secure, owner FROM webappsstore2_temp "
         "UNION ALL "
-        "SELECT * FROM webappsstore2 "
+        "SELECT scope, key, value, secure, owner FROM webappsstore2 "
           "WHERE NOT EXISTS ("
             "SELECT scope, key FROM webappsstore2_temp "
             "WHERE scope = webappsstore2.scope AND key = webappsstore2.key)"));
   NS_ENSURE_SUCCESS(rv, rv);
 
   // carry deletion to both the temporary table and the disk table
   rv = mConnection->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
         "CREATE TEMPORARY TRIGGER webappsstore2_view_delete_trigger "
@@ -297,18 +298,18 @@ nsDOMStoragePersistentDB::EnsureLoadTemp
 
   if (!mTempTableLoads.Get(aStorage->GetScopeDBKey(), &timeStamp)) {
     nsresult rv;
 
     rv = MaybeCommitInsertTransaction();
     NS_ENSURE_SUCCESS(rv, rv);
 
     nsCOMPtr<mozIStorageStatement> stmt = mStatements.GetCachedStatement(
-      "INSERT INTO webappsstore2_temp "
-        "SELECT * FROM webappsstore2 "
+      "INSERT INTO webappsstore2_temp (scope, key, value, secure, owner) "
+        "SELECT scope, key, value, secure, owner FROM webappsstore2 "
         "WHERE scope = :scope "
           "AND NOT EXISTS ( "
             "SELECT scope, key FROM webappsstore2_temp "
             "WHERE scope = webappsstore2.scope AND key = webappsstore2.key "
           ") "
     );
     NS_ENSURE_STATE(stmt);
     mozStorageStatementScoper scope(stmt);
@@ -339,18 +340,18 @@ nsDOMStoragePersistentDB::FlushTemporary
   if (!data->mForce && 
       ((TimeStamp::Now() - aData).ToSeconds() < TEMP_TABLE_MAX_AGE))
     return PL_DHASH_NEXT;
 
   {
     nsCOMPtr<mozIStorageStatement> stmt =
       data->mDB->mStatements.GetCachedStatement(
         "INSERT OR REPLACE INTO webappsstore2 "
-         "SELECT * FROM webappsstore2_temp "
-         "WHERE scope = :scope "
+         "SELECT scope, key, value, secure, owner FROM webappsstore2_temp "
+         "WHERE scope = :scope AND modified = 1"
       );
     NS_ENSURE_TRUE(stmt, PL_DHASH_STOP);
     mozStorageStatementScoper scope(stmt);
 
     data->mRV = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("scope"), aKey);
     NS_ENSURE_SUCCESS(data->mRV, PL_DHASH_STOP);
 
     data->mRV = stmt->Execute();
@@ -534,18 +535,18 @@ nsDOMStoragePersistentDB::SetKey(DOMStor
   if (usage > aQuota) {
     return NS_ERROR_DOM_QUOTA_REACHED;
   }
 
   rv = EnsureInsertTransaction();
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<mozIStorageStatement> stmt = mStatements.GetCachedStatement(
-    "INSERT OR REPLACE INTO webappsstore2_temp (scope, key, value, secure) "
-    "VALUES (:scope, :key, :value, :secure) "
+    "INSERT OR REPLACE INTO webappsstore2_temp (scope, key, value, secure, modified) "
+    "VALUES (:scope, :key, :value, :secure, 1) "
   );
   NS_ENSURE_STATE(stmt);
   mozStorageStatementScoper scopeinsert(stmt);
 
   rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("scope"),
                                   aStorage->GetScopeDBKey());
   NS_ENSURE_SUCCESS(rv, rv);
   rv = stmt->BindStringByName(NS_LITERAL_CSTRING("key"),
@@ -583,17 +584,17 @@ nsDOMStoragePersistentDB::SetSecure(DOMS
   rv = EnsureLoadTemporaryTableForStorage(aStorage);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = EnsureInsertTransaction();
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<mozIStorageStatement> stmt = mStatements.GetCachedStatement(
     "UPDATE webappsstore2_temp "
-    "SET secure = :secure "
+    "SET secure = :secure, modified = 1 "
     "WHERE scope = :scope "
       "AND key = :key "
   );
   NS_ENSURE_STATE(stmt);
   mozStorageStatementScoper scope(stmt);
 
   rv = stmt->BindUTF8StringByName(NS_LITERAL_CSTRING("scope"),
                                   aStorage->GetScopeDBKey());