Bug 726002 - Clear some big nsTArrays as early as possible in updates. r=dcamp
authorGian-Carlo Pascutto <gpascutto@mozilla.com>
Mon, 13 Feb 2012 17:10:22 +0100
changeset 90285 35bf0d62cc305d4caf00aeb448cb93a915462a83
parent 90284 a010dcf1a973cfd49c8a02547ea915e27867eabc
child 90286 1a8ab74003238590350a247a7fbff43d00054a73
push id136
push userlsblakk@mozilla.com
push dateFri, 01 Jun 2012 02:39:32 +0000
treeherdermozilla-release@7ebf7352c959 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdcamp
bugs726002
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 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;