Bug 726002 - Clear some big nsTArrays as early as possible in updates. r=dcamp
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Wed, 15 Aug 2012 09:05:18 +0200
changeset 108374 aa57f7757c972a2439ec984ca7e004950aa54034
parent 108373 3dbf00bb0d706214e23436b26276dd72e12b8c9e
child 108375 0f125c23208cbf947ffc654710cacfa48448d1f2
push id214
push userakeybl@mozilla.com
push dateWed, 14 Nov 2012 20:38:59 +0000
treeherdermozilla-release@c8b08ec8e1aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdcamp
bugs726002
milestone17.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 726002 - Clear some big nsTArrays as early as possible in updates. r=dcamp
toolkit/components/url-classifier/Classifier.cpp
toolkit/components/url-classifier/HashStore.h
toolkit/components/url-classifier/LookupCache.cpp
toolkit/components/url-classifier/LookupCache.h
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -526,16 +526,17 @@ Classifier::ApplyTableUpdates(nsTArray<T
   if (!prefixSet) {
     return NS_ERROR_FAILURE;
   }
   nsTArray<PRUint32> AddPrefixHashes;
   rv = prefixSet->GetPrefixes(&AddPrefixHashes);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = store->AugmentAdds(AddPrefixHashes);
   NS_ENSURE_SUCCESS(rv, rv);
+  AddPrefixHashes.Clear();
 
   uint32 applied = 0;
   bool updateFreshness = false;
 
   for (uint32 i = 0; i < aUpdates->Length(); i++) {
     TableUpdate *update = aUpdates->ElementAt(i);
     if (!update || !update->TableName().Equals(store->TableName()))
       continue;
--- a/toolkit/components/url-classifier/HashStore.h
+++ b/toolkit/components/url-classifier/HashStore.h
@@ -115,20 +115,20 @@ public:
 
   const nsCString& TableName() const { return mTableName; };
 
   nsresult Open();
   nsresult AugmentAdds(const nsTArray<PRUint32>& aPrefixes);
 
   ChunkSet& AddChunks() { return mAddChunks; }
   ChunkSet& SubChunks() { return mSubChunks; }
-  const AddPrefixArray& AddPrefixes() const { return mAddPrefixes; }
-  const AddCompleteArray& AddCompletes() const { return mAddCompletes; }
-  const SubPrefixArray& SubPrefixes() const { return mSubPrefixes; }
-  const SubCompleteArray& SubCompletes() const { return mSubCompletes; }
+  AddPrefixArray& AddPrefixes() { return mAddPrefixes; }
+  AddCompleteArray& AddCompletes() { return mAddCompletes; }
+  SubPrefixArray& SubPrefixes() { return mSubPrefixes; }
+  SubCompleteArray& SubCompletes() { return mSubCompletes; }
 
   // =======
   // Updates
   // =======
   // Begin the update process.  Reads the store into memory.
   nsresult BeginUpdate();
 
   // Imports the data from a TableUpdate.
--- a/toolkit/components/url-classifier/LookupCache.cpp
+++ b/toolkit/components/url-classifier/LookupCache.cpp
@@ -166,27 +166,28 @@ LookupCache::Reset()
 
   Clear();
 
   return NS_OK;
 }
 
 
 nsresult
-LookupCache::Build(const AddPrefixArray& aAddPrefixes,
-                   const AddCompleteArray& aAddCompletes)
+LookupCache::Build(AddPrefixArray& aAddPrefixes,
+                   AddCompleteArray& aAddCompletes)
 {
   Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LC_COMPLETIONS,
                         static_cast<PRUint32>(aAddCompletes.Length()));
 
   mCompletions.Clear();
   mCompletions.SetCapacity(aAddCompletes.Length());
   for (uint32 i = 0; i < aAddCompletes.Length(); i++) {
     mCompletions.AppendElement(aAddCompletes[i].CompleteHash());
   }
+  aAddCompletes.Clear();
   mCompletions.Sort();
 
   Telemetry::Accumulate(Telemetry::URLCLASSIFIER_LC_PREFIXES,
                         static_cast<PRUint32>(aAddPrefixes.Length()));
 
   nsresult rv = ConstructPrefixSet(aAddPrefixes);
   NS_ENSURE_SUCCESS(rv, rv);
   mPrimed = true;
@@ -674,32 +675,32 @@ LookupCache::GetHostKeys(const nsACStrin
 }
 
 bool LookupCache::IsPrimed()
 {
   return mPrimed;
 }
 
 nsresult
-LookupCache::ConstructPrefixSet(const AddPrefixArray& aAddPrefixes)
+LookupCache::ConstructPrefixSet(AddPrefixArray& aAddPrefixes)
 {
   Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_PS_CONSTRUCT_TIME> timer;
 
   FallibleTArray<PRUint32> array;
   nsresult rv;
   if (!array.SetCapacity(aAddPrefixes.Length())) {
     rv = NS_ERROR_OUT_OF_MEMORY;
     goto error_bailout;
   }
 
   for (uint32 i = 0; i < aAddPrefixes.Length(); i++) {
     array.AppendElement(aAddPrefixes[i].PrefixHash().ToUint32());
   }
+  aAddPrefixes.Clear();
 
-  // clear old tree
   if (array.IsEmpty()) {
     // DB is empty, but put a sentinel to show that we looked
     array.AppendElement(0);
   }
   // PrefixSet requires sorted order
   array.Sort();
 
   // construct new one, replace old entries
--- a/toolkit/components/url-classifier/LookupCache.h
+++ b/toolkit/components/url-classifier/LookupCache.h
@@ -132,18 +132,19 @@ public:
 
   LookupCache(const nsACString& aTableName, nsIFile* aStoreFile);
   ~LookupCache();
 
   const nsCString &TableName() const { return mTableName; }
 
   nsresult Init();
   nsresult Open();
-  nsresult Build(const AddPrefixArray& aAddPrefixes,
-                 const AddCompleteArray& aAddCompletes);
+  // This will Clear() the passed arrays when done.
+  nsresult Build(AddPrefixArray& aAddPrefixes,
+                 AddCompleteArray& aAddCompletes);
   nsresult GetPrefixes(nsTArray<PRUint32>* aAddPrefixes);
 
 #if DEBUG && defined(PR_LOGGING)
   void Dump();
 #endif
   nsresult WriteFile();
   nsresult Has(const Completion& aCompletion,
                const Completion& aHostkey,
@@ -155,19 +156,20 @@ public:
 private:
 
   void Clear();
   nsresult Reset();
   void UpdateHeader();
   nsresult ReadHeader();
   nsresult EnsureSizeConsistent();
   nsresult ReadCompletions();
-  // Construct a Prefix Set with known prefixes
   nsresult LoadPrefixSet();
-  nsresult ConstructPrefixSet(const AddPrefixArray& aAddPrefixes);
+  // Construct a Prefix Set with known prefixes.
+  // This will Clear() aAddPrefixes when done.
+  nsresult ConstructPrefixSet(AddPrefixArray& aAddPrefixes);
 
   struct Header {
     uint32 magic;
     uint32 version;
     uint32 numCompletions;
   };
   Header mHeader;