Bug 145817 - GraphicsContext state stack wasting lots of memory when empty.
Summary: GraphicsContext state stack wasting lots of memory when empty.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Canvas (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Andreas Kling
URL:
Keywords: Performance
Depends on:
Blocks:
 
Reported: 2015-06-09 14:33 PDT by Andreas Kling
Modified: 2015-06-09 17:47 PDT (History)
3 users (show)

See Also:


Attachments
Patch (2.19 KB, patch)
2015-06-09 14:53 PDT, Andreas Kling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Kling 2015-06-09 14:33:27 PDT
GraphicsContext::restore() uses removeLast() which never nukes the Vector<State>'s backing store.
This means that we always have capacity for at least 16 states in each GraphicsContext that has ever save()d.
Since canvas elements have a persistent GraphicsContext, this adds up to a bunch of memory with multiple canvases around.
Comment 1 Andreas Kling 2015-06-09 14:53:33 PDT
Created attachment 254604 [details]
Patch
Comment 2 Geoffrey Garen 2015-06-09 15:14:17 PDT
Comment on attachment 254604 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=254604&action=review

r=me

> Source/WebCore/platform/graphics/GraphicsContext.cpp:140
> +    // 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();

Should Vector do this automatically?
Comment 3 Geoffrey Garen 2015-06-09 15:14:47 PDT
To elaborate, I really hate it that std::vector does not do this automatically. At the limit, you have to add a call to clear to every client!
Comment 4 Andreas Kling 2015-06-09 16:19:05 PDT
(In reply to comment #3)
> To elaborate, I really hate it that std::vector does not do this
> automatically. At the limit, you have to add a call to clear to every client!

I guess you mean WTF::Vector.
We can totes do that. Let's separate the issues though.
Comment 5 Geoffrey Garen 2015-06-09 16:32:41 PDT
> > To elaborate, I really hate it that std::vector does not do this
> > automatically. At the limit, you have to add a call to clear to every client!
> 
> I guess you mean WTF::Vector.
> We can totes do that. Let's separate the issues though.

No, I mean that std::vector never ever shrinks until you call shrink_to_fit, which is super annoying, while WTF::Vector often shrinks automatically, but misses in this case.
Comment 6 WebKit Commit Bot 2015-06-09 17:47:23 PDT
Comment on attachment 254604 [details]
Patch

Clearing flags on attachment: 254604

Committed r185396: <http://trac.webkit.org/changeset/185396>
Comment 7 WebKit Commit Bot 2015-06-09 17:47:26 PDT
All reviewed patches have been landed.  Closing bug.