<?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>251701</bug_id>
          
          <creation_ts>2023-02-03 10:32:30 -0800</creation_ts>
          <short_desc>Style::RuleFeatureSet wastes vector capacity</short_desc>
          <delta_ts>2023-02-08 14:14:03 -0800</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>WebKit Local 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>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Simon Fraser (smfr)">simon.fraser</reporter>
          <assigned_to name="Antti Koivisto">koivisto</assigned_to>
          <cc>koivisto</cc>
    
    <cc>ntim</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1930925</commentid>
    <comment_count>0</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2023-02-03 10:32:30 -0800</bug_when>
    <thetext>Using the patch in bug 186698, and testing on a wikipedia page, we see that RuleFeatureSet::collectFeatures() wastes a 5KB vector capacity:

Wasted capacity: 5472 bytes (used 672 of 6144 bytes, utilization: 10.94%) - 24 allocations
1   0x2fcec0bec WebCore::Style::RuleFeatureSet::collectFeatures(WebCore::Style::RuleData const&amp;)
2   0x2fcec5807 WebCore::Style::RuleSet::addRule(WebCore::Style::RuleData&amp;&amp;, unsigned int, unsigned int)
3   0x2fcec5790 WebCore::Style::RuleSet::addRule(WebCore::StyleRule const&amp;, unsigned int, unsigned int)
4   0x2fcee8922 WTF::Vector&lt;WebCore::Style::InvalidationRuleSet, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt;* WebCore::Style::ensureInvalidationRuleSets&lt;WTF::AtomString, WTF::Vector&lt;WebCore::Style::RuleFeature, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt;, WTF::DefaultHash&lt;WTF::AtomString&gt;, WTF::HashTraits&lt;WTF::AtomString&gt; &gt;(WTF::AtomString const&amp;, WTF::HashMap&lt;WTF::AtomString, std::__1::unique_ptr&lt;WTF::Vector&lt;WebCore::Style::InvalidationRuleSet, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt;, std::__1::default_delete&lt;WTF::Vector&lt;WebCore::Style::InvalidationRuleSet, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt; &gt; &gt;, WTF::DefaultHash&lt;WTF::AtomString&gt;, WTF::HashTraits&lt;WTF::AtomString&gt;, WTF::HashTraits&lt;std::__1::unique_ptr&lt;WTF::Vector&lt;WebCore::Style::InvalidationRuleSet, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt;, std::__1::default_delete&lt;WTF::Vector&lt;WebCore::Style::InvalidationRuleSet, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt; &gt; &gt; &gt;, WTF::HashTableTraits&gt;&amp;, WTF::HashMap&lt;WTF::AtomString, std::__1::unique_ptr&lt;WTF::Vector&lt;WebCore::Style::RuleFeature, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt;, std::__1::default_delete&lt;WTF::Vector&lt;WebCore::Style::RuleFeature, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt; &gt; &gt;, WTF::DefaultHash&lt;WTF::AtomString&gt;, WTF::HashTraits&lt;WTF::AtomString&gt;, WTF::HashTraits&lt;std::__1::unique_ptr&lt;WTF::Vector&lt;WebCore::Style::RuleFeature, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt;, std::__1::default_delete&lt;WTF::Vector&lt;WebCore::Style::RuleFeature, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc&gt; &gt; &gt; &gt;, WTF::HashTableTraits&gt; const&amp;)
5   0x2fceaeb0d WebCore::Style::ClassChangeInvalidation::computeInvalidation(WebCore::SpaceSplitString const&amp;, WebCore::SpaceSplitString const&amp;)
6   0x2fc3955e1 WebCore::Style::ClassChangeInvalidation::ClassChangeInvalidation(WebCore::Element&amp;, WebCore::SpaceSplitString const&amp;, WebCore::SpaceSplitString const&amp;)
7   0x2fc386170 WebCore::Element::classAttributeChanged(WTF::AtomString const&amp;)
8   0x2fc385b17 WebCore::Element::attributeChanged(WebCore::QualifiedName const&amp;, WTF::AtomString const&amp;, WTF::AtomString const&amp;, WebCore::Element::AttributeModificationReason)
9   0x2fc38fe34 WebCore::Element::didModifyAttribute(WebCore::QualifiedName const&amp;, WTF::AtomString const&amp;, WTF::AtomString const&amp;)
10  0x2fc384df3 WebCore::Element::setAttributeInternal(unsigned int, WebCore::QualifiedName const&amp;, WTF::AtomString const&amp;, WebCore::Element::SynchronizationOfLazyAttribute)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1930926</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-02-03 10:33:07 -0800</bug_when>
    <thetext>&lt;rdar://problem/105011534&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1931133</commentid>
    <comment_count>2</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2023-02-04 13:59:32 -0800</bug_when>
    <thetext>Maybe need a shrinkToFit() somewhere like ensureInvalidationRuleSets()?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1931134</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2023-02-04 14:00:21 -0800</bug_when>
    <thetext>There&apos;s bloat out of these two call sites:

ClassChangeInvalidation::computeInvalidation()
PseudoClassChangeInvalidation::collectRuleSets();</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1931976</commentid>
    <comment_count>4</comment_count>
    <who name="Antti Koivisto">koivisto</who>
    <bug_when>2023-02-08 02:48:46 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/9806</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1932079</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2023-02-08 10:44:42 -0800</bug_when>
    <thetext>Committed 260021@main (381f8ae629b0): &lt;https://commits.webkit.org/260021@main&gt;

Reviewed commits have been landed. Closing PR #9806 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1932084</commentid>
    <comment_count>6</comment_count>
    <who name="Bri Harris">bharris9</who>
    <bug_when>2023-02-08 11:19:51 -0800</bug_when>
    <thetext>Re-opening for pull request https://github.com/WebKit/WebKit/pull/9830</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>