Bug 1353618 - Optimize storage of MozPromise::mThenValues. r=gerald, a=gchang
authorJW Wang <jwwang@mozilla.com>
Fri, 31 Mar 2017 18:41:29 +0800
changeset 395722 ab11d51947eb9ec46018150c96784bcc15d565e8
parent 395721 46bb49526e17c04ae6eaae4d24a50a04e92b64d2
child 395723 b6746564d765c9a749f7808b0984fa8ab13d2180
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald, gchang
bugs1353618
milestone54.0a2
Bug 1353618 - Optimize storage of MozPromise::mThenValues. r=gerald, a=gchang 1. Set the capacity to 1 when IsExclusive is true. 2. Set it to 3 because Try shows we never have more the 3 elements when IsExclusive is false. MozReview-Commit-ID: dmIeE6ZTeh
xpcom/threads/MozPromise.h
--- a/xpcom/threads/MozPromise.h
+++ b/xpcom/threads/MozPromise.h
@@ -916,17 +916,19 @@ protected:
   };
 
   const char* mCreationSite; // For logging
   Mutex mMutex;
   ResolveOrRejectValue mValue;
 #ifdef PROMISE_DEBUG
   uint32_t mMagic1 = sMagic;
 #endif
-  nsTArray<RefPtr<ThenValueBase>> mThenValues;
+  // Try shows we never have more than 3 elements when IsExclusive is false.
+  // So '3' is a good value to avoid heap allocation in most cases.
+  AutoTArray<RefPtr<ThenValueBase>, IsExclusive ? 1 : 3> mThenValues;
 #ifdef PROMISE_DEBUG
   uint32_t mMagic2 = sMagic;
 #endif
   nsTArray<RefPtr<Private>> mChainedPromises;
 #ifdef PROMISE_DEBUG
   uint32_t mMagic3 = sMagic;
 #endif
   bool mHaveRequest;