Bug 1482956 - Use an AutoTArray in PaintTask to reduce heap allocations. r=nical
authorRyan Hunt <rhunt@eqrion.net>
Mon, 13 Aug 2018 12:22:18 -0500
changeset 486656 0448f28516031e7d8429e6fc5c1a0fe2e83a5dfe
parent 486655 2300b4b766cab3f534187dd12947219d907333f4
child 486657 2698e4d327ef9a088c93fad43d65f88a97ae9614
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1482956
milestone63.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 1482956 - Use an AutoTArray in PaintTask to reduce heap allocations. r=nical There should only ever be at most four TextureClients here, so allocated a vector seems wasteful.
gfx/layers/PaintThread.cpp
gfx/layers/PaintThread.h
gfx/layers/client/ContentClient.cpp
gfx/layers/client/TiledContentClient.cpp
gfx/layers/client/TiledContentClient.h
--- a/gfx/layers/PaintThread.cpp
+++ b/gfx/layers/PaintThread.cpp
@@ -31,17 +31,17 @@
 namespace mozilla {
 namespace layers {
 
 using namespace gfx;
 
 void
 PaintTask::DropTextureClients()
 {
-  mClients.clear();
+  mClients.Clear();
 }
 
 StaticAutoPtr<PaintThread> PaintThread::sSingleton;
 StaticRefPtr<nsIThread> PaintThread::sThread;
 PlatformThreadId PaintThread::sThreadId;
 
 PaintThread::PaintThread()
 {
--- a/gfx/layers/PaintThread.h
+++ b/gfx/layers/PaintThread.h
@@ -31,17 +31,17 @@ class PaintTask {
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PaintTask)
 public:
   PaintTask() {}
 
   void DropTextureClients();
 
   RefPtr<gfx::DrawTarget> mTarget;
   RefPtr<gfx::DrawTargetCapture> mCapture;
-  std::vector<RefPtr<TextureClient>> mClients;
+  AutoTArray<RefPtr<TextureClient>, 4> mClients;
 
 protected:
   virtual ~PaintTask() {}
 };
 
 class CompositorBridgeChild;
 
 class PaintThread final
--- a/gfx/layers/client/ContentClient.cpp
+++ b/gfx/layers/client/ContentClient.cpp
@@ -271,19 +271,19 @@ ContentClient::BeginPaint(PaintedLayer* 
     mBuffer = newBuffer;
   }
 
   NS_ASSERTION(canHaveRotation || mBuffer->BufferRotation() == IntPoint(0,0),
                "Rotation disabled, but we have nonzero rotation?");
 
   if (result.mAsyncPaint) {
     result.mAsyncTask->mTarget = mBuffer->GetBufferTarget();
-    result.mAsyncTask->mClients.push_back(mBuffer->GetClient());
+    result.mAsyncTask->mClients.AppendElement(mBuffer->GetClient());
     if (mBuffer->GetClientOnWhite()) {
-      result.mAsyncTask->mClients.push_back(mBuffer->GetClientOnWhite());
+      result.mAsyncTask->mClients.AppendElement(mBuffer->GetClientOnWhite());
     }
   }
 
   nsIntRegion invalidate;
   invalidate.Sub(aLayer->GetValidRegion(), dest.mBufferRect);
   result.mRegionToInvalidate.Or(result.mRegionToInvalidate, invalidate);
 
   result.mClip = DrawRegionClip::DRAW;
@@ -882,19 +882,19 @@ ContentClientDoubleBuffered::FinalizeFra
   OpenMode openMode = aPaintState.mAsyncPaint
                         ? OpenMode::OPEN_READ_ASYNC
                         : OpenMode::OPEN_READ_ONLY;
 
   if (mFrontBuffer->Lock(openMode)) {
     mBuffer->UpdateDestinationFrom(*mFrontBuffer, updateRegion.GetBounds());
 
     if (aPaintState.mAsyncPaint) {
-      aPaintState.mAsyncTask->mClients.push_back(mFrontBuffer->GetClient());
+      aPaintState.mAsyncTask->mClients.AppendElement(mFrontBuffer->GetClient());
       if (mFrontBuffer->GetClientOnWhite()) {
-        aPaintState.mAsyncTask->mClients.push_back(mFrontBuffer->GetClientOnWhite());
+        aPaintState.mAsyncTask->mClients.AppendElement(mFrontBuffer->GetClientOnWhite());
       }
     }
 
     mFrontBuffer->Unlock();
   }
 }
 
 void
--- a/gfx/layers/client/TiledContentClient.cpp
+++ b/gfx/layers/client/TiledContentClient.cpp
@@ -430,17 +430,17 @@ TileClient::Flip()
 }
 
 void
 TileClient::ValidateFromFront(const nsIntRegion& aDirtyRegion,
                               const nsIntRegion& aVisibleRegion,
                               gfx::DrawTarget* aBackBuffer,
                               TilePaintFlags aFlags,
                               IntRect* aCopiedRect,
-                              std::vector<RefPtr<TextureClient>>* aClients)
+                              AutoTArray<RefPtr<TextureClient>, 4>* aClients)
 {
   if (!mBackBuffer || !mFrontBuffer) {
     return;
   }
 
   gfx::IntSize tileSize = mFrontBuffer->GetSize();
   const IntRect tileRect = IntRect(0, 0, tileSize.width, tileSize.height);
 
@@ -474,19 +474,19 @@ TileClient::ValidateFromFront(const nsIn
   if (!frontBuffer.Succeeded()) {
     return;
   }
 
   RefPtr<gfx::SourceSurface> frontSurface = frontBuffer->Snapshot();
   aBackBuffer->CopySurface(frontSurface, rectToCopy, rectToCopy.TopLeft());
 
   if (aFlags & TilePaintFlags::Async) {
-    aClients->push_back(mFrontBuffer);
+    aClients->AppendElement(mFrontBuffer);
     if (mFrontBufferOnWhite) {
-      aClients->push_back(mFrontBufferOnWhite);
+      aClients->AppendElement(mFrontBufferOnWhite);
     }
   }
 
   mInvalidBack.Sub(mInvalidBack, aVisibleRegion);
 }
 
 void
 TileClient::DiscardFrontBuffer()
@@ -711,20 +711,20 @@ TileClient::AcquireBackBuffer(Compositab
   // Construct a capture draw target if necessary
   RefPtr<DrawTargetCapture> capture;
   if (aFlags & TilePaintFlags::Async) {
     capture = Factory::CreateCaptureDrawTargetForTarget(target, gfxPrefs::LayersOMTPCaptureLimit());
     target = capture;
   }
 
   // Gather texture clients
-  std::vector<RefPtr<TextureClient>> clients;
-  clients.push_back(RefPtr<TextureClient>(mBackBuffer));
+  AutoTArray<RefPtr<TextureClient>, 4> clients;
+  clients.AppendElement(RefPtr<TextureClient>(mBackBuffer));
   if (mBackBufferOnWhite) {
-    clients.push_back(mBackBufferOnWhite);
+    clients.AppendElement(mBackBufferOnWhite);
   }
 
   // Copy from the front buerr to the back if necessary
   IntRect updatedRect;
   ValidateFromFront(aDirtyRegion,
                     aVisibleRegion,
                     target,
                     aFlags,
--- a/gfx/layers/client/TiledContentClient.h
+++ b/gfx/layers/client/TiledContentClient.h
@@ -52,17 +52,17 @@ enum class TilePaintFlags : uint8_t {
 MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(TilePaintFlags)
 
 struct AcquiredBackBuffer
 {
   AcquiredBackBuffer(gfx::DrawTarget* aTarget,
                      gfx::DrawTargetCapture* aCapture,
                      gfx::DrawTarget* aBackBuffer,
                      const gfx::IntRect& aUpdatedRect,
-                     std::vector<RefPtr<TextureClient>>&& aTextureClients)
+                     AutoTArray<RefPtr<TextureClient>, 4>&& aTextureClients)
     : mTarget(aTarget)
     , mCapture(aCapture)
     , mBackBuffer(aBackBuffer)
     , mUpdatedRect(aUpdatedRect)
     , mTextureClients(aTextureClients)
   {}
 
   AcquiredBackBuffer(const AcquiredBackBuffer&) = delete;
@@ -70,17 +70,17 @@ struct AcquiredBackBuffer
 
   AcquiredBackBuffer(AcquiredBackBuffer&&) = default;
   AcquiredBackBuffer& operator=(AcquiredBackBuffer&&) = default;
 
   RefPtr<gfx::DrawTarget> mTarget;
   RefPtr<gfx::DrawTargetCapture> mCapture;
   RefPtr<gfx::DrawTarget> mBackBuffer;
   gfx::IntRect mUpdatedRect;
-  std::vector<RefPtr<TextureClient>> mTextureClients;
+  AutoTArray<RefPtr<TextureClient>, 4> mTextureClients;
 };
 
 /**
  * Represent a single tile in tiled buffer. The buffer keeps tiles,
  * each tile keeps a reference to a texture client and a read-lock. This
  * read-lock is used to help implement a copy-on-write mechanism. The tile
  * should be locked before being sent to the compositor. The compositor should
  * unlock the read-lock as soon as it has finished with the buffer in the
@@ -199,17 +199,17 @@ private:
    * Copies dirty pixels from the front buffer into the back buffer,
    * and records the copied region in aAddPaintedRegion.
    */
   void ValidateFromFront(const nsIntRegion& aDirtyRegion,
                          const nsIntRegion& aVisibleRegion,
                          gfx::DrawTarget* aBackBuffer,
                          TilePaintFlags aFlags,
                          gfx::IntRect* aCopiedRegion,
-                         std::vector<RefPtr<TextureClient>>* aClients);
+                         AutoTArray<RefPtr<TextureClient>, 4>* aClients);
 };
 
 /**
  * This struct stores all the data necessary to perform a paint so that it
  * doesn't need to be recalculated on every repeated transaction.
  */
 struct BasicTiledLayerPaintData {
   /*