Bug 1569094 - Optimize cache-miss path in GetDrawFetchLimits. r=lsalzman
authorJeff Gilbert <jgilbert@mozilla.com>
Fri, 26 Jul 2019 04:04:08 +0000
changeset 484799 9813549331af43eaebc60e0114458c12533431b5
parent 484798 3b6f2ab0c825c11dd96b0b09a1f61701539a9ff8
child 484800 ca660ab1e0c169d8956e2c1a8a271203eaea5e8e
push id36348
push usershindli@mozilla.com
push dateFri, 26 Jul 2019 09:43:08 +0000
treeherdermozilla-central@9813549331af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1569094
milestone70.0a1
first release with
nightly linux32
9813549331af / 70.0a1 / 20190726094308 / files
nightly linux64
9813549331af / 70.0a1 / 20190726094308 / files
nightly mac
9813549331af / 70.0a1 / 20190726094308 / files
nightly win32
9813549331af / 70.0a1 / 20190726094308 / files
nightly win64
9813549331af / 70.0a1 / 20190726094308 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1569094 - Optimize cache-miss path in GetDrawFetchLimits. r=lsalzman Differential Revision: https://phabricator.services.mozilla.com/D39456
dom/canvas/CacheInvalidator.cpp
dom/canvas/CacheInvalidator.h
dom/canvas/WebGLProgram.cpp
--- a/dom/canvas/CacheInvalidator.cpp
+++ b/dom/canvas/CacheInvalidator.cpp
@@ -15,36 +15,32 @@ void CacheInvalidator::InvalidateCaches(
     const auto pEntry = *itr;
     pEntry->OnInvalidate();
     MOZ_ASSERT(mCaches.find(pEntry) == mCaches.end());
   }
 }
 
 // -
 
-AbstractCache::InvalidatorListT AbstractCache::ResetInvalidators(
-    InvalidatorListT&& newList) {
+void AbstractCache::ResetInvalidators(InvalidatorListT&& newList) {
   for (const auto& cur : mInvalidators) {
     if (cur) {
       (void)cur->mCaches.erase(this);
     }
   }
 
-  auto ret = std::move(mInvalidators);
   mInvalidators = std::move(newList);
 
   for (const auto& cur : mInvalidators) {
     // Don't assert that we insert, since there may be dupes in `invalidators`.
     // (and it's not worth removing the dupes)
     if (cur) {
       (void)cur->mCaches.insert(this);
     }
   }
-
-  return ret;
 }
 
 void AbstractCache::AddInvalidator(const CacheInvalidator& x) {
   mInvalidators.push_back(&x);
   x.mCaches.insert(this);
 }
 
 }  // namespace mozilla
--- a/dom/canvas/CacheInvalidator.h
+++ b/dom/canvas/CacheInvalidator.h
@@ -73,18 +73,17 @@ class AbstractCache {
     ResetInvalidators(std::move(invalidators));
   }
 
   virtual ~AbstractCache() { ResetInvalidators({}); }
 
  public:
   virtual void OnInvalidate() = 0;
 
-  InvalidatorListT ResetInvalidators(
-      InvalidatorListT&&);  // Returns the old list.
+  void ResetInvalidators(InvalidatorListT&&);
   void AddInvalidator(const CacheInvalidator&);
 };
 
 // -
 
 template <typename T>
 class CacheMaybe : public AbstractCache {
   Maybe<T> mVal;
--- a/dom/canvas/WebGLProgram.cpp
+++ b/dom/canvas/WebGLProgram.cpp
@@ -574,32 +574,39 @@ const webgl::CachedDrawFetchLimits*
 webgl::LinkedProgramInfo::GetDrawFetchLimits() const {
   const auto& webgl = prog->mContext;
   const auto& vao = webgl->mBoundVertexArray;
 
   const auto found = mDrawFetchCache.Find(vao);
   if (found) return found;
 
   std::vector<const CacheInvalidator*> cacheDeps;
+  cacheDeps.reserve(2 + this->attribs.size());
   cacheDeps.push_back(vao.get());
   cacheDeps.push_back(&webgl->mGenericVertexAttribTypeInvalidator);
 
   {
     // We have to ensure that every enabled attrib array (not just the active
     // ones) has a non-null buffer.
-    uint32_t i = 0;
+    bool err = false;
     for (const auto& cur : vao->mAttribs) {
-      if (cur.mEnabled && !cur.mBuf) {
-        webgl->ErrorInvalidOperation(
-            "Vertex attrib array %u is enabled but"
-            " has no buffer bound.",
-            i);
-        return nullptr;
+      err |= (cur.mEnabled && !cur.mBuf);
+    }
+    if (MOZ_UNLIKELY(err)) {
+      uint32_t i = 0;
+      for (const auto& cur : vao->mAttribs) {
+        if (cur.mEnabled && !cur.mBuf) {
+          webgl->ErrorInvalidOperation(
+              "Vertex attrib array %u is enabled but"
+              " has no buffer bound.",
+              i);
+          return nullptr;
+        }
+        i++;
       }
-      i++;
     }
   }
 
   bool hasActiveAttrib = false;
   bool hasActiveDivisor0 = false;
   webgl::CachedDrawFetchLimits fetchLimits = {UINT64_MAX, UINT64_MAX};
   fetchLimits.usedBuffers.reserve(this->attribs.size());