Title: [211206] trunk/Source/WebCore
Revision
211206
Author
[email protected]
Date
2017-01-26 01:21:46 -0800 (Thu, 26 Jan 2017)

Log Message

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: trunk/Source/WebCore/ChangeLog (211205 => 211206)


--- trunk/Source/WebCore/ChangeLog	2017-01-26 09:19:48 UTC (rev 211205)
+++ trunk/Source/WebCore/ChangeLog	2017-01-26 09:21:46 UTC (rev 211206)
@@ -1,3 +1,27 @@
+2017-01-26  Zan Dobersek  <[email protected]>
+
+        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-26  Miguel Gomez  <[email protected]>
 
         [GTK] WebProcess from WebKitGtk+ 2.15.3 SIGSEVs in WebCore::GraphicsContext3D::drawArrays(unsigned int, int, int) at Source/WebCore/platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:740

Modified: trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp (211205 => 211206)


--- trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2017-01-26 09:19:48 UTC (rev 211205)
+++ trunk/Source/WebCore/platform/graphics/cairo/ImageBufferCairo.cpp	2017-01-26 09:21:46 UTC (rev 211206)
@@ -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
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to