<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>145817</bug_id>
          
          <creation_ts>2015-06-09 14:33:27 -0700</creation_ts>
          <short_desc>GraphicsContext state stack wasting lots of memory when empty.</short_desc>
          <delta_ts>2015-06-09 17:47:26 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Canvas</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>Performance</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Andreas Kling">kling</reporter>
          <assigned_to name="Andreas Kling">kling</assigned_to>
          <cc>commit-queue</cc>
    
    <cc>ggaren</cc>
    
    <cc>kling</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1100800</commentid>
    <comment_count>0</comment_count>
    <who name="Andreas Kling">kling</who>
    <bug_when>2015-06-09 14:33:27 -0700</bug_when>
    <thetext>GraphicsContext::restore() uses removeLast() which never nukes the Vector&lt;State&gt;&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1100804</commentid>
    <comment_count>1</comment_count>
      <attachid>254604</attachid>
    <who name="Andreas Kling">kling</who>
    <bug_when>2015-06-09 14:53:33 -0700</bug_when>
    <thetext>Created attachment 254604
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1100812</commentid>
    <comment_count>2</comment_count>
      <attachid>254604</attachid>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2015-06-09 15:14:17 -0700</bug_when>
    <thetext>Comment on attachment 254604
Patch

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

r=me

&gt; Source/WebCore/platform/graphics/GraphicsContext.cpp:140
&gt; +    // Make sure we deallocate the state stack buffer when it goes empty.
&gt; +    // Canvas elements will immediately save() again, but that goes into inline capacity.
&gt; +    if (m_stack.isEmpty())
&gt; +        m_stack.clear();

Should Vector do this automatically?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1100813</commentid>
    <comment_count>3</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2015-06-09 15:14:47 -0700</bug_when>
    <thetext>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!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1100843</commentid>
    <comment_count>4</comment_count>
    <who name="Andreas Kling">kling</who>
    <bug_when>2015-06-09 16:19:05 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; To elaborate, I really hate it that std::vector does not do this
&gt; 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&apos;s separate the issues though.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1100853</commentid>
    <comment_count>5</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2015-06-09 16:32:41 -0700</bug_when>
    <thetext>&gt; &gt; To elaborate, I really hate it that std::vector does not do this
&gt; &gt; automatically. At the limit, you have to add a call to clear to every client!
&gt; 
&gt; I guess you mean WTF::Vector.
&gt; We can totes do that. Let&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1100874</commentid>
    <comment_count>6</comment_count>
      <attachid>254604</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-06-09 17:47:23 -0700</bug_when>
    <thetext>Comment on attachment 254604
Patch

Clearing flags on attachment: 254604

Committed r185396: &lt;http://trac.webkit.org/changeset/185396&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1100875</commentid>
    <comment_count>7</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2015-06-09 17:47:26 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>254604</attachid>
            <date>2015-06-09 14:53:33 -0700</date>
            <delta_ts>2015-06-09 17:47:23 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-145817.diff</filename>
            <type>text/plain</type>
            <size>2243</size>
            <attacher name="Andreas Kling">kling</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZyBiL1NvdXJjZS9XZWJDb3JlL0No
YW5nZUxvZwppbmRleCA2OWYxZDU4Li42MTM4ZGEzIDEwMDY0NAotLS0gYS9Tb3VyY2UvV2ViQ29y
ZS9DaGFuZ2VMb2cKKysrIGIvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMjMg
QEAKKzIwMTUtMDYtMDkgIEFuZHJlYXMgS2xpbmcgIDxha2xpbmdAYXBwbGUuY29tPgorCisgICAg
ICAgIEdyYXBoaWNzQ29udGV4dCBzdGF0ZSBzdGFjayB3YXN0aW5nIGxvdHMgb2YgbWVtb3J5IHdo
ZW4gZW1wdHkuCisgICAgICAgIDxodHRwczovL3dlYmtpdC5vcmcvYi8xNDU4MTc+CisKKyAgICAg
ICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT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