Bug 251701 - Style::RuleFeatureSet wastes vector capacity
Summary: Style::RuleFeatureSet wastes vector capacity
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Antti Koivisto
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-02-03 10:32 PST by Simon Fraser (smfr)
Modified: 2023-02-08 14:14 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Fraser (smfr) 2023-02-03 10:32:30 PST
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&)
2   0x2fcec5807 WebCore::Style::RuleSet::addRule(WebCore::Style::RuleData&&, unsigned int, unsigned int)
3   0x2fcec5790 WebCore::Style::RuleSet::addRule(WebCore::StyleRule const&, unsigned int, unsigned int)
4   0x2fcee8922 WTF::Vector<WebCore::Style::InvalidationRuleSet, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc>* WebCore::Style::ensureInvalidationRuleSets<WTF::AtomString, WTF::Vector<WebCore::Style::RuleFeature, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc>, WTF::DefaultHash<WTF::AtomString>, WTF::HashTraits<WTF::AtomString> >(WTF::AtomString const&, WTF::HashMap<WTF::AtomString, std::__1::unique_ptr<WTF::Vector<WebCore::Style::InvalidationRuleSet, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc>, std::__1::default_delete<WTF::Vector<WebCore::Style::InvalidationRuleSet, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> > >, WTF::DefaultHash<WTF::AtomString>, WTF::HashTraits<WTF::AtomString>, WTF::HashTraits<std::__1::unique_ptr<WTF::Vector<WebCore::Style::InvalidationRuleSet, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc>, std::__1::default_delete<WTF::Vector<WebCore::Style::InvalidationRuleSet, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> > > >, WTF::HashTableTraits>&, WTF::HashMap<WTF::AtomString, std::__1::unique_ptr<WTF::Vector<WebCore::Style::RuleFeature, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc>, std::__1::default_delete<WTF::Vector<WebCore::Style::RuleFeature, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> > >, WTF::DefaultHash<WTF::AtomString>, WTF::HashTraits<WTF::AtomString>, WTF::HashTraits<std::__1::unique_ptr<WTF::Vector<WebCore::Style::RuleFeature, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc>, std::__1::default_delete<WTF::Vector<WebCore::Style::RuleFeature, 0ul, WTF::CrashOnOverflow, 16ul, WTF::FastMalloc> > > >, WTF::HashTableTraits> const&)
5   0x2fceaeb0d WebCore::Style::ClassChangeInvalidation::computeInvalidation(WebCore::SpaceSplitString const&, WebCore::SpaceSplitString const&)
6   0x2fc3955e1 WebCore::Style::ClassChangeInvalidation::ClassChangeInvalidation(WebCore::Element&, WebCore::SpaceSplitString const&, WebCore::SpaceSplitString const&)
7   0x2fc386170 WebCore::Element::classAttributeChanged(WTF::AtomString const&)
8   0x2fc385b17 WebCore::Element::attributeChanged(WebCore::QualifiedName const&, WTF::AtomString const&, WTF::AtomString const&, WebCore::Element::AttributeModificationReason)
9   0x2fc38fe34 WebCore::Element::didModifyAttribute(WebCore::QualifiedName const&, WTF::AtomString const&, WTF::AtomString const&)
10  0x2fc384df3 WebCore::Element::setAttributeInternal(unsigned int, WebCore::QualifiedName const&, WTF::AtomString const&, WebCore::Element::SynchronizationOfLazyAttribute)
Comment 1 Radar WebKit Bug Importer 2023-02-03 10:33:07 PST
<rdar://problem/105011534>
Comment 2 Simon Fraser (smfr) 2023-02-04 13:59:32 PST
Maybe need a shrinkToFit() somewhere like ensureInvalidationRuleSets()?
Comment 3 Simon Fraser (smfr) 2023-02-04 14:00:21 PST
There's bloat out of these two call sites:

ClassChangeInvalidation::computeInvalidation()
PseudoClassChangeInvalidation::collectRuleSets();
Comment 4 Antti Koivisto 2023-02-08 02:48:46 PST
Pull request: https://github.com/WebKit/WebKit/pull/9806
Comment 5 EWS 2023-02-08 10:44:42 PST
Committed 260021@main (381f8ae629b0): <https://commits.webkit.org/260021@main>

Reviewed commits have been landed. Closing PR #9806 and removing active labels.
Comment 6 Bri Harris 2023-02-08 11:19:51 PST
Re-opening for pull request https://github.com/WebKit/WebKit/pull/9830