<?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>108229</bug_id>
          
          <creation_ts>2013-01-29 14:30:06 -0800</creation_ts>
          <short_desc>CSS matched properties cache exploding when mapped SVG attributes are updated frequently</short_desc>
          <delta_ts>2022-07-13 13:57:14 -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>CSS</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>CONFIGURATION CHANGED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>108345</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Florin Malita">fmalita</reporter>
          <assigned_to name="Florin Malita">fmalita</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>eric</cc>
    
    <cc>kling</cc>
    
    <cc>koivisto</cc>
    
    <cc>krit</cc>
    
    <cc>pdr</cc>
    
    <cc>schenney</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>819332</commentid>
    <comment_count>0</comment_count>
      <attachid>185308</attachid>
    <who name="Florin Malita">fmalita</who>
    <bug_when>2013-01-29 14:30:06 -0800</bug_when>
    <thetext>Created attachment 185308
Leaks memory, eventually crashes Chromium.

https://code.google.com/p/chromium/issues/detail?id=172221

Several issues at play here:

1) the matched properties cache is never swept:

StyleResolver::addToMatchedPropertiesCache():

    if (++m_matchedPropertiesCacheAdditionsSinceLastSweep &gt;= matchedDeclarationCacheAdditionsBetweenSweeps) {
        static const unsigned matchedDeclarationCacheSweepTimeInSeconds = 60;
        m_matchedPropertiesCacheSweepTimer.startOneShot(matchedDeclarationCacheSweepTimeInSeconds);
    }

Since we keep updating the props, the timer keeps getting reset and never fires. I&apos;ll post a patch to leave the timer alone if already armed.

StyleResolver::matchAllRules(
2) matched SVG properties are cacheable

I&apos;m not familiar with this area, but it seems strange that SVG attributes result in cacheable matched properties, while the equivalent CSS test (divs, background-color updates) yields non-cacheable matched properties.

For inline style we explicitly make a caching decision:
StyleResolver::matchAllRules(
        // Inline style is immutable as long as there is no CSSOM wrapper.
        // FIXME: Media control shadow trees seem to have problems with caching.
        bool isInlineStyleCacheable = !m_styledElement-&gt;inlineStyle()-&gt;isMutable() &amp;&amp; !m_styledElement-&gt;isInShadowTree();

while for presentational attributes we never re-evaluate cacheability based on isMutable.

I don&apos;t understand enough of what&apos;s going on here to call it a bug, but it does seem a bit odd to have this asymmetry - someone should confirm that it&apos;s intended.


3) SVG matched properties do not get a deterministic matched properties hash key

This is because StyledElement::makePresentationAttributeCacheKey() doesn&apos;t support SVG attributes:

void StyledElement::makePresentationAttributeCacheKey(PresentationAttributeCacheKey&amp; result) const
{    
    // FIXME: Enable for SVG.
    if (namespaceURI() != xhtmlNamespaceURI)
        return;

=&gt; SVG StylePropertySets are effectively non-cacheable (in the presentation attribute cache)
=&gt; rebuildPresentationAttributeStyle() always allocates a new StylePropertySet
=&gt; the hash computed in StyleResolver::applyMatchedProperties() is always different (is based on MatchedProperties contents which bundles pointers to StylePropertySets)
=&gt; SVG matched properties are always added to the matched properties cache, even if equivalent entries already exist

This probably needs fixing: add SVG support to StyledElement::makePresentationAttributeCacheKey() to enable proper SVG data hashing in both the presentation attribute cache and the matched properties cache.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>823176</commentid>
    <comment_count>1</comment_count>
    <who name="Florin Malita">fmalita</who>
    <bug_when>2013-02-01 13:12:49 -0800</bug_when>
    <thetext>Andreas, Antti: I&apos;m not familiar with styling and trying to understand what the correct high-level behavior should be here.

For a CSS test where I&apos;m modifying &apos;background-color&apos; on a &lt;div&gt; dynamically, the resulting MatchResult is non-cacheable because of the following snippet in StyleResolver::matchAllRules():

    // Now check our inline style attribute.
    if (m_matchAuthorAndUserStyles &amp;&amp; m_styledElement &amp;&amp; m_styledElement-&gt;inlineStyle()) {
        // Inline style is immutable as long as there is no CSSOM wrapper.
        // FIXME: Media control shadow trees seem to have problems with caching.
        bool isInlineStyleCacheable = !m_styledElement-&gt;inlineStyle()-&gt;isMutable() &amp;&amp; !m_styledElement-&gt;isInShadowTree();
        // FIXME: Constify.
        addElementStyleProperties(result, m_styledElement-&gt;inlineStyle(), isInlineStyleCacheable);
    }


Is the intent to prevent caching of script-modifiable matched properties? That would make sense, since with a 1 min purge timer on the matched properties cache one could use up lots of memory otherwise.

But for SVG attributes there is no such mechanism - the resulting matched properties are cached unconditionally on the presentational attributes path:

    // Now check author rules, beginning first with presentational attributes mapped from HTML.
    if (m_styledElement) {
        addElementStyleProperties(result, m_styledElement-&gt;presentationAttributeStyle());


I guess the question is: should SVG attributes always yield non-cacheable matched properties?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1883297</commentid>
    <comment_count>2</comment_count>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2022-07-13 13:57:14 -0700</bug_when>
    <thetext>WebKit seems to use the least amount of memory or other resources (compared to Blink and Gecko).</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>185308</attachid>
            <date>2013-01-29 14:30:06 -0800</date>
            <delta_ts>2013-01-29 14:30:06 -0800</delta_ts>
            <desc>Leaks memory, eventually crashes Chromium.</desc>
            <filename>leak.html</filename>
            <type>text/html</type>
            <size>2322</size>
            <attacher name="Florin Malita">fmalita</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0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GVpZ2h0ID0gIjUwMHB4IjsKICAgICAgICAgICAgICAgIHN2Zy5zZXRBdHRyaWJ1dGUoInZl
cnNpb24iLCAiMS4xIik7CiAgICAgICAgICAgICAgICBkaXYuYXBwZW5kQ2hpbGQoc3ZnKTsKICAg
ICAgICAgICAgICAgIGNyZWF0ZUVsZW1lbnRzKCk7ICAgICAgICAgICAgICAgCiAgICAgICAgICAg
IH0KCgogICAgICAgICAgICBmdW5jdGlvbiBjcmVhdGVFbGVtZW50cygpewoKICAgICAgICAgICAg
ICAgIHJlbW92ZUVsZW1lbnRzKCk7CgogICAgICAgICAgICAgICAgZm9yKHZhciBpID0gMDsgaSA8
IDUwMDsgaSsrKXsKICAgICAgICAgICAgICAgICAgICB2YXIgZWxlbWVudCA9IGNyZWF0ZVN2Z0Vs
ZW1lbnQoImNpcmNsZSIpOwogICAgICAgICAgICAgICAgICAgIGVsZW1lbnQuc2V0QXR0cmlidXRl
KCJyIiwgTWF0aC5yYW5kb20oKSAqIDEwKTsKICAgICAgICAgICAgICAgICAgICB2YXIgdHJhbnNm
b3JtID0gInRyYW5zbGF0ZSgiICsgTWF0aC5yb3VuZChNYXRoLnJhbmRvbSgpICogNjAwKSArICIs
IiArIE1hdGgucm91bmQoTWF0aC5yYW5kb20oKSAqIDUwMCkgKyAiKSI7CiAgICAgICAgICAgICAg
ICAgICAgZWxlbWVudC5zZXRBdHRyaWJ1dGUoInRyYW5zZm9ybSIsIHRyYW5zZm9ybSk7CiAgICAg
ICAgICAgICAgICAgICAgc3ZnLmFwcGVuZENoaWxkKGVsZW1lbnQpOwogICAgICAgICAgICAgICAg
ICAgIGVsZW1lbnQuc2V0QXR0cmlidXRlKCJmaWxsIiwgIiNDQzAwMDAiKTsKICAgICAgICAgICAg
ICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICAgICAgZnVuY3Rpb24gcmVtb3ZlRWxlbWVudHMo
KXsKICAgICAgICAgICAgICAgIHdoaWxlKHN2Zy5oYXNDaGlsZE5vZGVzKCkgKXsKICAgICAgICAg
ICAgICAgICAgICBzdmcucmVtb3ZlQ2hpbGQoc3ZnLmxhc3RDaGlsZCk7CiAgICAgICAgICAgICAg
ICB9ICAgICAgICAgICAgICAgCiAgICAgICAgICAgIH0KCgogICAgICAgICAgICBmdW5jdGlvbiBj
cmVhdGVTdmdFbGVtZW50IChuYW1lKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gZG9jdW1lbnQu
Y3JlYXRlRWxlbWVudE5TKCJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIsIG5hbWUpOwogICAg
ICAgICAgICB9CgogICAgICAgICAgICBmdW5jdGlvbiBzdG9wKCl7CiAgICAgICAgICAgICAgICBj
bGVhckludGVydmFsKGludGVydmFsKQogICAgICAgICAgICB9CgoKICAgICAgICA8L3NjcmlwdD4K
ICAgIDwvaGVhZD4KICAgIDxib2R5IHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNGRkZGRkYiPgog
ICAgICAgIDxkaXYgaWQ9InN2Z2RpdiIgc3R5bGU9IndpZHRoOjYwMHB4OyBoZWlnaHQ6NTAwcHg7
Ij48L2Rpdj4KICAgICAgICA8aW5wdXQgdHlwZT0iYnV0dG9uIiB2YWx1ZT0ic3RhcnQiIG9uY2xp
Y2s9InN0YXJ0KCkiPgogICAgICAgIDxpbnB1dCB0eXBlPSJidXR0b24iIHZhbHVlPSJzdG9wIiBv
bmNsaWNrPSJzdG9wKCkiPgogICAgPC9ib2R5PgogICAgPC9odG1sPgoK
</data>

          </attachment>
      

    </bug>

</bugzilla>