Title: [211799] releases/WebKitGTK/webkit-2.14/Source/WebCore
Revision
211799
Author
carlo...@webkit.org
Date
2017-02-07 01:38:43 -0800 (Tue, 07 Feb 2017)

Log Message

Merge r211206 - ImageBufferCairo: cairo_image_surface should use bmalloc-allocated memory
https://bugs.webkit.org/show_bug.cgi?id=165751

Reviewed by Carlos Garcia Campos.

Allocate the underlying memory for cairo_image_surface objects through FastMalloc.
This way we can steer such large allocations away from the default libc allocator.

Objects of this class can create Cairo surfaces that need as much as 4MB of memory
for the underlying pixel buffer. Allocating such objects through the default
libc allocator can lead to increased memory usage because of non-optimal allocation
strategy in libc. In contrast, bmalloc performs large allocations by directly using
mmap() to reserve the necessary memory.

The improvements can be significant. On nytimes.com, with the threaded version of
the CoordinatedGraphics system, the memory consumption can drop by roughly 20%.

* platform/graphics/cairo/ImageBufferCairo.cpp:
(WebCore::ImageBuffer::ImageBuffer): Zero-allocate the necessary memory via FastMalloc.
Tie that memory lifetime to the lifetime of the surface by using
cairo_surface_set_user_data() with the specific user data key.

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/ChangeLog (211798 => 211799)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/ChangeLog	2017-02-07 09:34:18 UTC (rev 211798)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/ChangeLog	2017-02-07 09:38:43 UTC (rev 211799)
@@ -1,3 +1,27 @@
+2017-01-26  Zan Dobersek  <zdober...@igalia.com>
+
+        ImageBufferCairo: cairo_image_surface should use bmalloc-allocated memory
+        https://bugs.webkit.org/show_bug.cgi?id=165751
+
+        Reviewed by Carlos Garcia Campos.
+
+        Allocate the underlying memory for cairo_image_surface objects through FastMalloc.
+        This way we can steer such large allocations away from the default libc allocator.
+
+        Objects of this class can create Cairo surfaces that need as much as 4MB of memory
+        for the underlying pixel buffer. Allocating such objects through the default
+        libc allocator can lead to increased memory usage because of non-optimal allocation
+        strategy in libc. In contrast, bmalloc performs large allocations by directly using
+        mmap() to reserve the necessary memory.
+
+        The improvements can be significant. On nytimes.com, with the threaded version of
+        the CoordinatedGraphics system, the memory consumption can drop by roughly 20%.
+
+        * platform/graphics/cairo/ImageBufferCairo.cpp:
+        (WebCore::ImageBuffer::ImageBuffer): Zero-allocate the necessary memory via FastMalloc.
+        Tie that memory lifetime to the lifetime of the surface by using
+        cairo_surface_set_user_data() with the specific user data key.
+
 2017-01-30  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [Threaded Compositor] Crash in GraphicsContext3D::deleteTexture when destroying TextureMapperPlatformLayerProxy

Modified: releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp (211798 => 211799)


--- releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2017-02-07 09:34:18 UTC (rev 211798)
+++ releases/WebKitGTK/webkit-2.14/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2017-02-07 09:38:43 UTC (rev 211799)
@@ -218,8 +218,16 @@
 #else
     ASSERT(m_data.m_renderingMode != Accelerated);
 #endif
-        m_data.m_surface = adoptRef(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m_size.width(), m_size.height()));
+    {
+        static cairo_user_data_key_t s_surfaceDataKey;
 
+        int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, m_size.width());
+        auto* surfaceData = fastZeroedMalloc(m_size.height() * stride);
+
+        m_data.m_surface = adoptRef(cairo_image_surface_create_for_data(static_cast<unsigned char*>(surfaceData), CAIRO_FORMAT_ARGB32, m_size.width(), m_size.height(), stride));
+        cairo_surface_set_user_data(m_data.m_surface.get(), &s_surfaceDataKey, surfaceData, [](void* data) { fastFree(data); });
+    }
+
     if (cairo_surface_status(m_data.m_surface.get()) != CAIRO_STATUS_SUCCESS)
         return;  // create will notice we didn't set m_initialized and fail.
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to