Bug 1448091 - Part 2: AccessibleHandler: Don't repeatedly and unnecessarily refresh the cache after the first change. r=MarcoZ, a=jcristau
authorJames Teh <jteh@mozilla.com>
Fri, 23 Mar 2018 11:53:01 -0400
changeset 462899 880bdfaff98ec3098a2fd2ea50c29c52b540ee53
parent 462898 50c5d93932ca95a27cb9ddb5d9af37dc0c0d0ce1
child 462900 8b2c7b0546e96f508fc2608f3cc8a627518948d2
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMarcoZ, jcristau
bugs1448091
milestone60.0
Bug 1448091 - Part 2: AccessibleHandler: Don't repeatedly and unnecessarily refresh the cache after the first change. r=MarcoZ, a=jcristau The singleton AccessibleHandlerControl maintains a global cache generation counter which is incremented whenever any node is changed. The handler for each node tracks the cache generation at the time its cache was initialized. To check whether the cache needs to be updated, the handler compares its generation against the global generation from AccessibleHandlerControl. If they differ, it refreshes the cache. Previously, the handler didn't update its cache generation after refreshing. This meant that every single query after the first change would refresh the whole cache, even if there wasn't a second change. This resulted in a huge number of wasted cache updates for clients such as JAWS which hold onto accessibles, rather than releasing them and fetching them again for each update. MozReview-Commit-ID: 80d4n1cIjzQ
accessible/ipc/win/handler/AccessibleHandler.cpp
--- a/accessible/ipc/win/handler/AccessibleHandler.cpp
+++ b/accessible/ipc/win/handler/AccessibleHandler.cpp
@@ -202,24 +202,31 @@ AccessibleHandler::MaybeUpdateCachedData
 {
   RefPtr<AccessibleHandlerControl> ctl(gControlFactory.GetOrCreateSingleton());
   if (!ctl) {
     return E_OUTOFMEMORY;
   }
 
   uint32_t gen = ctl->GetCacheGen();
   if (gen == mCacheGen) {
+    // Cache is already up to date.
     return S_OK;
   }
 
   if (!mCachedData.mGeckoBackChannel) {
     return E_POINTER;
   }
 
-  return mCachedData.mGeckoBackChannel->Refresh(&mCachedData.mDynamicData);
+  HRESULT hr =  mCachedData.mGeckoBackChannel->Refresh(&mCachedData.mDynamicData);
+  if (SUCCEEDED(hr)) {
+    // We just updated the cache, so update this object's cache generation
+    // so we only update the cache again after the next change.
+    mCacheGen = gen;
+  }
+  return hr;
 }
 
 HRESULT
 AccessibleHandler::GetAllTextInfo(BSTR* aText)
 {
   MOZ_ASSERT(mCachedData.mGeckoBackChannel);
 
   ClearTextCache();