Skip to content

Commit

Permalink
Merge r185396 - GraphicsContext state stack wasting lots of memory wh…
Browse files Browse the repository at this point in the history
…en empty.

<https://webkit.org/b/145817>

Reviewed by Geoffrey Garen.

Give the GraphicsContextState stack an inline capacity of 1, and make sure
to free any heap-allocated backing store when the stack goes empty.

The 1 is because HTMLCanvasElement keeps one "save" on the underlying
GraphicsContext at all times, and this prevents those canvases from always
sitting on an empty stack with 16 capacity.

This saves ~520 kB on cnet.com video pages.

* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::restore):
* platform/graphics/GraphicsContext.h:
  • Loading branch information
Andreas Kling authored and carlosgcampos committed Jul 7, 2015
1 parent de07bfe commit f083aed
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,23 @@
2015-06-09 Andreas Kling <akling@apple.com>

GraphicsContext state stack wasting lots of memory when empty.
<https://webkit.org/b/145817>

Reviewed by Geoffrey Garen.

Give the GraphicsContextState stack an inline capacity of 1, and make sure
to free any heap-allocated backing store when the stack goes empty.

The 1 is because HTMLCanvasElement keeps one "save" on the underlying
GraphicsContext at all times, and this prevents those canvases from always
sitting on an empty stack with 16 capacity.

This saves ~520 kB on cnet.com video pages.

* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::restore):
* platform/graphics/GraphicsContext.h:

2015-06-09 Said Abou-Hallawa <sabouhallawa@apple.com>

SVG Fragment is not rendered if it is the css background image of an HTML element
Expand Down
5 changes: 5 additions & 0 deletions Source/WebCore/platform/graphics/GraphicsContext.cpp
Expand Up @@ -134,6 +134,11 @@ void GraphicsContext::restore()
m_state = m_stack.last();
m_stack.removeLast();

// Make sure we deallocate the state stack buffer when it goes empty.
// Canvas elements will immediately save() again, but that goes into inline capacity.
if (m_stack.isEmpty())
m_stack.clear();

restorePlatformState();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/platform/graphics/GraphicsContext.h
Expand Up @@ -555,7 +555,7 @@ namespace WebCore {
GraphicsContextPlatformPrivate* m_data;

GraphicsContextState m_state;
Vector<GraphicsContextState> m_stack;
Vector<GraphicsContextState, 1> m_stack;
bool m_updatingControlTints;
unsigned m_transparencyCount;
};
Expand Down

0 comments on commit f083aed

Please sign in to comment.