Bug 1353618 - Optimize storage of MozPromise::mThenValues. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 31 Mar 2017 18:41:29 +0800
changeset 556002 479ea47a3736a251d2a7bb0c36b0564fb6f112bb
parent 556001 19bd85ea883884b90637fcb2584fbe523e6cb116
child 622749 42a1a005e71f3a96f580798476ac53481e8af51e
push id52395
push userjwwang@mozilla.com
push dateWed, 05 Apr 2017 07:15:44 +0000
bugs1353618
milestone55.0a1
Bug 1353618 - Optimize storage of MozPromise::mThenValues. 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
@@ -921,17 +921,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;