Changeset 252208 in webkit


Ignore:
Timestamp:
Nov 7, 2019 3:01:20 PM (4 years ago)
Author:
Antti Koivisto
Message:

Factor matched declarations cache into a class
https://bugs.webkit.org/show_bug.cgi?id=203972

Reviewed by Zalan Bujtas.

Move the code out from StyleResolver and rename "matched properties cache" -> "matched declarations cache"
to better describe it.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • css/ElementRuleCollector.cpp:

(WebCore::ElementRuleCollector::declarationsForOrigin):

Add a helper.

(WebCore::ElementRuleCollector::transferMatchedRules):

Reserve vector capacity before adding rules.

(WebCore::ElementRuleCollector::addMatchedProperties):

  • css/ElementRuleCollector.h:

(WebCore::MatchResult::operator== const):
(WebCore::MatchResult::operator!= const):

Remove the unneeded inline capacity so we can just use MatchResult itself in the cache.

  • css/RuleSet.cpp:

(WebCore::RuleSet::addChildRules):

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::StyleResolver):
(WebCore::StyleResolver::invalidateMatchedDeclarationsCache):
(WebCore::StyleResolver::clearCachedDeclarationsAffectedByViewportUnits):
(WebCore::StyleResolver::applyMatchedProperties):
(WebCore::StyleResolver::sweepMatchedPropertiesCache): Deleted.
(WebCore::StyleResolver::computeMatchedPropertiesHash): Deleted.
(WebCore::StyleResolver::findFromMatchedPropertiesCache): Deleted.
(WebCore::StyleResolver::addToMatchedPropertiesCache): Deleted.
(WebCore::StyleResolver::invalidateMatchedPropertiesCache): Deleted.
(WebCore::StyleResolver::clearCachedPropertiesAffectedByViewportUnits): Deleted.
(WebCore::isCacheableInMatchedPropertiesCache): Deleted.

  • css/StyleResolver.h:

(WebCore::StyleResolver::MatchedPropertiesCacheItem::MatchedPropertiesCacheItem): Deleted.

  • dom/Document.cpp:

(WebCore::Document::invalidateMatchedPropertiesCacheAndForceStyleRecalc):
(WebCore::Document::updateViewportUnitsOnResize):

  • page/Page.cpp:

(WebCore::Page::updateStyleAfterChangeInEnvironment):

  • style/MatchedDeclarationsCache.cpp: Added.

(WebCore::Style::MatchedDeclarationsCache::MatchedDeclarationsCache):
(WebCore::Style::MatchedDeclarationsCache::isCacheable):
(WebCore::Style::MatchedDeclarationsCache::computeHash):
(WebCore::Style::MatchedDeclarationsCache::find):
(WebCore::Style::MatchedDeclarationsCache::add):
(WebCore::Style::MatchedDeclarationsCache::invalidate):
(WebCore::Style::MatchedDeclarationsCache::clearEntriesAffectedByViewportUnits):
(WebCore::Style::MatchedDeclarationsCache::sweep):

  • style/MatchedDeclarationsCache.h: Added.
  • style/StyleTreeResolver.cpp:

(WebCore::Style::TreeResolver::resolveElement):

Location:
trunk/Source/WebCore
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252207 r252208  
     12019-11-07  Antti Koivisto  <antti@apple.com>
     2
     3        Factor matched declarations cache into a class
     4        https://bugs.webkit.org/show_bug.cgi?id=203972
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Move the code out from StyleResolver and rename "matched properties cache" -> "matched declarations cache"
     9        to better describe it.
     10
     11        * Sources.txt:
     12        * WebCore.xcodeproj/project.pbxproj:
     13        * css/ElementRuleCollector.cpp:
     14        (WebCore::ElementRuleCollector::declarationsForOrigin):
     15
     16        Add a helper.
     17
     18        (WebCore::ElementRuleCollector::transferMatchedRules):
     19
     20        Reserve vector capacity before adding rules.
     21
     22        (WebCore::ElementRuleCollector::addMatchedProperties):
     23        * css/ElementRuleCollector.h:
     24        (WebCore::MatchResult::operator== const):
     25        (WebCore::MatchResult::operator!= const):
     26
     27        Remove the unneeded inline capacity so we can just use MatchResult itself in the cache.
     28
     29        * css/RuleSet.cpp:
     30        (WebCore::RuleSet::addChildRules):
     31        * css/StyleResolver.cpp:
     32        (WebCore::StyleResolver::StyleResolver):
     33        (WebCore::StyleResolver::invalidateMatchedDeclarationsCache):
     34        (WebCore::StyleResolver::clearCachedDeclarationsAffectedByViewportUnits):
     35        (WebCore::StyleResolver::applyMatchedProperties):
     36        (WebCore::StyleResolver::sweepMatchedPropertiesCache): Deleted.
     37        (WebCore::StyleResolver::computeMatchedPropertiesHash): Deleted.
     38        (WebCore::StyleResolver::findFromMatchedPropertiesCache): Deleted.
     39        (WebCore::StyleResolver::addToMatchedPropertiesCache): Deleted.
     40        (WebCore::StyleResolver::invalidateMatchedPropertiesCache): Deleted.
     41        (WebCore::StyleResolver::clearCachedPropertiesAffectedByViewportUnits): Deleted.
     42        (WebCore::isCacheableInMatchedPropertiesCache): Deleted.
     43        * css/StyleResolver.h:
     44        (WebCore::StyleResolver::MatchedPropertiesCacheItem::MatchedPropertiesCacheItem): Deleted.
     45        * dom/Document.cpp:
     46        (WebCore::Document::invalidateMatchedPropertiesCacheAndForceStyleRecalc):
     47        (WebCore::Document::updateViewportUnitsOnResize):
     48        * page/Page.cpp:
     49        (WebCore::Page::updateStyleAfterChangeInEnvironment):
     50        * style/MatchedDeclarationsCache.cpp: Added.
     51        (WebCore::Style::MatchedDeclarationsCache::MatchedDeclarationsCache):
     52        (WebCore::Style::MatchedDeclarationsCache::isCacheable):
     53        (WebCore::Style::MatchedDeclarationsCache::computeHash):
     54        (WebCore::Style::MatchedDeclarationsCache::find):
     55        (WebCore::Style::MatchedDeclarationsCache::add):
     56        (WebCore::Style::MatchedDeclarationsCache::invalidate):
     57        (WebCore::Style::MatchedDeclarationsCache::clearEntriesAffectedByViewportUnits):
     58        (WebCore::Style::MatchedDeclarationsCache::sweep):
     59        * style/MatchedDeclarationsCache.h: Added.
     60        * style/StyleTreeResolver.cpp:
     61        (WebCore::Style::TreeResolver::resolveElement):
     62
    1632019-11-07  Eric Carlson  <eric.carlson@apple.com>
    264
  • trunk/Source/WebCore/Sources.txt

    r252036 r252208  
    23452345style/IdChangeInvalidation.cpp
    23462346style/InlineTextBoxStyle.cpp
     2347style/MatchedDeclarationsCache.cpp
    23472348style/PropertyCascade.cpp
    23482349style/StyleBuilder.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r252036 r252208  
    48104810                E44FA1851BCA6B5A0091B6EF /* ComposedTreeIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = E44FA1841BCA6B5A0091B6EF /* ComposedTreeIterator.h */; };
    48114811                E45322AC140CE267005A0F92 /* SelectorQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = E45322AA140CE267005A0F92 /* SelectorQuery.h */; };
     4812                E45BA6AA2374926C004DFC07 /* MatchedDeclarationsCache.h in Headers */ = {isa = PBXBuildFile; fileRef = E45BA6A82374926B004DFC07 /* MatchedDeclarationsCache.h */; };
    48124813                E4605FEC2166480900E53046 /* PrewarmInformation.h in Headers */ = {isa = PBXBuildFile; fileRef = E4605FEA2166480800E53046 /* PrewarmInformation.h */; settings = {ATTRIBUTES = (Private, ); }; };
    48134814                E461802D1C8DD2900026C02C /* StyleRelations.h in Headers */ = {isa = PBXBuildFile; fileRef = E461802C1C8DD2900026C02C /* StyleRelations.h */; };
     
    1512115122                E453903C0EAFD637003695C8 /* WidgetIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WidgetIOS.mm; sourceTree = "<group>"; };
    1512215123                E45390AD0EAFF4B5003695C8 /* SystemMemoryIOS.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SystemMemoryIOS.cpp; sourceTree = "<group>"; };
     15124                E45BA6A82374926B004DFC07 /* MatchedDeclarationsCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MatchedDeclarationsCache.h; sourceTree = "<group>"; };
     15125                E45BA6AB2374927B004DFC07 /* MatchedDeclarationsCache.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = MatchedDeclarationsCache.cpp; sourceTree = "<group>"; };
    1512315126                E4605FEA2166480800E53046 /* PrewarmInformation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrewarmInformation.h; sourceTree = "<group>"; };
    1512415127                E461802C1C8DD2900026C02C /* StyleRelations.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleRelations.h; sourceTree = "<group>"; };
     
    2696226965                                1C0106FE192594DF008A4201 /* InlineTextBoxStyle.cpp */,
    2696326966                                1C0106FF192594DF008A4201 /* InlineTextBoxStyle.h */,
     26967                                E45BA6AB2374927B004DFC07 /* MatchedDeclarationsCache.cpp */,
     26968                                E45BA6A82374926B004DFC07 /* MatchedDeclarationsCache.h */,
    2696426969                                E4ABABE52361A34200FA4345 /* PropertyCascade.cpp */,
    2696526970                                E4ABABE22361A32900FA4345 /* PropertyCascade.h */,
     
    3064030645                                FDF6BAF9134A4C9800822920 /* JSOfflineAudioCompletionEvent.h in Headers */,
    3064130646                                FDA9326716703BA9008982DC /* JSOfflineAudioContext.h in Headers */,
     30647                                E45BA6AA2374926C004DFC07 /* MatchedDeclarationsCache.h in Headers */,
    3064230648                                314877E61FAAB02500C05759 /* JSOffscreenCanvas.h in Headers */,
    3064330649                                3140C5271FDF558200D2A873 /* JSOffscreenCanvasRenderingContext2D.h in Headers */,
  • trunk/Source/WebCore/css/ElementRuleCollector.cpp

    r251690 r252208  
    160160}
    161161
     162
     163Vector<MatchedProperties>& ElementRuleCollector::declarationsForOrigin(MatchResult& matchResult, DeclarationOrigin declarationOrigin)
     164{
     165    switch (declarationOrigin) {
     166    case DeclarationOrigin::UserAgent: return matchResult.userAgentDeclarations;
     167    case DeclarationOrigin::User: return matchResult.userDeclarations;
     168    case DeclarationOrigin::Author: return matchResult.authorDeclarations;
     169    }
     170    ASSERT_NOT_REACHED();
     171    return matchResult.authorDeclarations;
     172}
     173
    162174void ElementRuleCollector::sortAndTransferMatchedRules(DeclarationOrigin declarationOrigin)
    163175{
     
    172184void ElementRuleCollector::transferMatchedRules(DeclarationOrigin declarationOrigin, Optional<Style::ScopeOrdinal> fromScope)
    173185{
    174     if (m_matchedRules.size() <= m_matchedRuleTransferIndex)
    175         return;
     186    if (m_mode != SelectorChecker::Mode::CollectingRules)
     187        declarationsForOrigin(m_result, declarationOrigin).reserveCapacity(m_matchedRules.size());
    176188
    177189    for (; m_matchedRuleTransferIndex < m_matchedRules.size(); ++m_matchedRuleTransferIndex) {
     
    659671    m_result.isCacheable = computeIsCacheable();
    660672
    661     switch (declarationOrigin) {
    662     case DeclarationOrigin::UserAgent:
    663         m_result.userAgentDeclarations.append(WTFMove(matchedProperties));
    664         break;
    665     case DeclarationOrigin::User:
    666         m_result.userDeclarations.append(WTFMove(matchedProperties));
    667         break;
    668     case DeclarationOrigin::Author:
    669         m_result.authorDeclarations.append(WTFMove(matchedProperties));
    670         break;
    671     }
     673    declarationsForOrigin(m_result, declarationOrigin).append(WTFMove(matchedProperties));
    672674}
    673675
  • trunk/Source/WebCore/css/ElementRuleCollector.h

    r251611 r252208  
    6363struct MatchResult {
    6464    bool isCacheable { true };
    65     Vector<MatchedProperties, 32> userAgentDeclarations;
    66     Vector<MatchedProperties, 32> userDeclarations;
    67     Vector<MatchedProperties, 32> authorDeclarations;
     65    Vector<MatchedProperties> userAgentDeclarations;
     66    Vector<MatchedProperties> userDeclarations;
     67    Vector<MatchedProperties> authorDeclarations;
     68
     69    bool operator==(const MatchResult& other) const
     70    {
     71        return isCacheable == other.isCacheable
     72            && userAgentDeclarations == other.userAgentDeclarations
     73            && userDeclarations == other.userDeclarations
     74            && authorDeclarations == other.authorDeclarations;
     75    }
     76    bool operator!=(const MatchResult& other) const { return !(*this == other); }
    6877
    6978    bool isEmpty() const { return userAgentDeclarations.isEmpty() && userDeclarations.isEmpty() && authorDeclarations.isEmpty(); }
     
    123132
    124133    enum class DeclarationOrigin { UserAgent, User, Author };
     134    static Vector<MatchedProperties>& declarationsForOrigin(MatchResult&, DeclarationOrigin);
    125135    void sortAndTransferMatchedRules(DeclarationOrigin);
    126136    void transferMatchedRules(DeclarationOrigin, Optional<Style::ScopeOrdinal> forScope = { });
  • trunk/Source/WebCore/css/RuleSet.cpp

    r250817 r252208  
    399399            // Add this font face to our set.
    400400            resolver->document().fontSelector().addFontFaceRule(downcast<StyleRuleFontFace>(*rule.get()), isInitiatingElementInUserAgentShadowTree);
    401             resolver->invalidateMatchedPropertiesCache();
     401            resolver->invalidateMatchedDeclarationsCache();
    402402        } else if (is<StyleRuleKeyframes>(*rule) && resolver)
    403403            resolver->addKeyframeStyle(downcast<StyleRuleKeyframes>(*rule));
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r251916 r252208  
    117117StyleResolver::StyleResolver(Document& document)
    118118    : m_ruleSets(*this)
    119     , m_matchedPropertiesCacheSweepTimer(*this, &StyleResolver::sweepMatchedPropertiesCache)
    120119    , m_document(document)
    121120#if ENABLE(CSS_DEVICE_ADAPTATION)
     
    195194    m_viewportStyleResolver->clearDocument();
    196195#endif
    197 }
    198 
    199 void StyleResolver::sweepMatchedPropertiesCache()
    200 {
    201     // Look for cache entries containing a style declaration with a single ref and remove them.
    202     // This may happen when an element attribute mutation causes it to generate a new inlineStyle()
    203     // or presentationAttributeStyle(), potentially leaving this cache with the last ref on the old one.
    204     auto hasOneRef = [](auto& declarations) {
    205         for (auto& matchedProperties : declarations) {
    206             if (matchedProperties.properties->hasOneRef())
    207                 return true;
    208         }
    209         return false;
    210     };
    211 
    212     m_matchedPropertiesCache.removeIf([&](auto& keyValue) {
    213         auto& entry = keyValue.value;
    214         return hasOneRef(entry.userAgentDeclarations) || hasOneRef(entry.userDeclarations) || hasOneRef(entry.authorDeclarations);
    215     });
    216 
    217     m_matchedPropertiesCacheAdditionsSinceLastSweep = 0;
    218196}
    219197
     
    11221100}
    11231101
    1124 unsigned StyleResolver::computeMatchedPropertiesHash(const MatchResult& matchResult)
    1125 {
    1126     return StringHasher::hashMemory(matchResult.userAgentDeclarations.data(), sizeof(MatchedProperties) * matchResult.userAgentDeclarations.size())
    1127         ^ StringHasher::hashMemory(matchResult.userDeclarations.data(), sizeof(MatchedProperties) * matchResult.userDeclarations.size())
    1128         ^ StringHasher::hashMemory(matchResult.authorDeclarations.data(), sizeof(MatchedProperties) * matchResult.authorDeclarations.size());
    1129 }
    1130 
    1131 const StyleResolver::MatchedPropertiesCacheItem* StyleResolver::findFromMatchedPropertiesCache(unsigned hash, const MatchResult& matchResult)
    1132 {
    1133     ASSERT(hash);
    1134 
    1135     MatchedPropertiesCache::iterator it = m_matchedPropertiesCache.find(hash);
    1136     if (it == m_matchedPropertiesCache.end())
    1137         return nullptr;
    1138 
    1139     auto& cacheItem = it->value;
    1140     if (matchResult.userAgentDeclarations != cacheItem.userAgentDeclarations || matchResult.userDeclarations != cacheItem.userDeclarations || matchResult.authorDeclarations != cacheItem.authorDeclarations)
    1141         return nullptr;
    1142 
    1143     return &cacheItem;
    1144 }
    1145 
    1146 void StyleResolver::addToMatchedPropertiesCache(const RenderStyle* style, const RenderStyle* parentStyle, unsigned hash, const MatchResult& matchResult)
    1147 {
    1148     static const unsigned matchedDeclarationCacheAdditionsBetweenSweeps = 100;
    1149     if (++m_matchedPropertiesCacheAdditionsSinceLastSweep >= matchedDeclarationCacheAdditionsBetweenSweeps
    1150         && !m_matchedPropertiesCacheSweepTimer.isActive()) {
    1151         static const Seconds matchedDeclarationCacheSweepTime { 1_min };
    1152         m_matchedPropertiesCacheSweepTimer.startOneShot(matchedDeclarationCacheSweepTime);
    1153     }
    1154 
    1155     ASSERT(hash);
    1156     // Note that we don't cache the original RenderStyle instance. It may be further modified.
    1157     // The RenderStyle in the cache is really just a holder for the substructures and never used as-is.
    1158     MatchedPropertiesCacheItem cacheItem(matchResult, style, parentStyle);
    1159     m_matchedPropertiesCache.add(hash, WTFMove(cacheItem));
    1160 }
    1161 
    1162 void StyleResolver::invalidateMatchedPropertiesCache()
    1163 {
    1164     m_matchedPropertiesCache.clear();
    1165 }
    1166 
    1167 void StyleResolver::clearCachedPropertiesAffectedByViewportUnits()
    1168 {
    1169     Vector<unsigned, 16> toRemove;
    1170     for (auto& cacheKeyValue : m_matchedPropertiesCache) {
    1171         if (cacheKeyValue.value.renderStyle->hasViewportUnits())
    1172             toRemove.append(cacheKeyValue.key);
    1173     }
    1174     for (auto key : toRemove)
    1175         m_matchedPropertiesCache.remove(key);
    1176 }
    1177 
    1178 static bool isCacheableInMatchedPropertiesCache(const Element& element, const RenderStyle* style, const RenderStyle* parentStyle)
    1179 {
    1180     // FIXME: Writing mode and direction properties modify state when applying to document element by calling
    1181     // Document::setWritingMode/DirectionSetOnDocumentElement. We can't skip the applying by caching.
    1182     if (&element == element.document().documentElement())
    1183         return false;
    1184     // content:attr() value depends on the element it is being applied to.
    1185     if (style->hasAttrContent() || (style->styleType() != PseudoId::None && parentStyle->hasAttrContent()))
    1186         return false;
    1187     if (style->hasAppearance())
    1188         return false;
    1189     if (style->zoom() != RenderStyle::initialZoom())
    1190         return false;
    1191     if (style->writingMode() != RenderStyle::initialWritingMode() || style->direction() != RenderStyle::initialDirection())
    1192         return false;
    1193     // The cache assumes static knowledge about which properties are inherited.
    1194     if (style->hasExplicitlyInheritedProperties())
    1195         return false;
    1196     return true;
    1197 }
    1198 
    1199 void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const Element& element, ShouldUseMatchedPropertiesCache shouldUseMatchedPropertiesCache)
     1102void StyleResolver::invalidateMatchedDeclarationsCache()
     1103{
     1104    m_matchedDeclarationsCache.invalidate();
     1105}
     1106
     1107void StyleResolver::clearCachedDeclarationsAffectedByViewportUnits()
     1108{
     1109    m_matchedDeclarationsCache.clearEntriesAffectedByViewportUnits();
     1110}
     1111
     1112void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const Element& element, UseMatchedDeclarationsCache useMatchedDeclarationsCache)
    12001113{
    12011114    State& state = m_state;
    1202     unsigned cacheHash = shouldUseMatchedPropertiesCache && matchResult.isCacheable ? computeMatchedPropertiesHash(matchResult) : 0;
     1115    unsigned cacheHash = useMatchedDeclarationsCache == UseMatchedDeclarationsCache::Yes ? Style::MatchedDeclarationsCache::computeHash(matchResult) : 0;
    12031116    auto includedProperties = Style::PropertyCascade::IncludedProperties::All;
    12041117
    1205     const MatchedPropertiesCacheItem* cacheItem = nullptr;
    1206     if (cacheHash && (cacheItem = findFromMatchedPropertiesCache(cacheHash, matchResult))
    1207         && isCacheableInMatchedPropertiesCache(element, state.style(), state.parentStyle())) {
     1118    auto& style = *state.style();
     1119    auto& parentStyle = *state.parentStyle();
     1120
     1121    auto* cacheEntry = m_matchedDeclarationsCache.find(cacheHash, matchResult);
     1122    if (cacheEntry && Style::MatchedDeclarationsCache::isCacheable(element, style, parentStyle)) {
    12081123        // We can build up the style by copying non-inherited properties from an earlier style object built using the same exact
    12091124        // style declarations. We then only need to apply the inherited properties, if any, as their values can depend on the
    12101125        // element context. This is fast and saves memory by reusing the style data structures.
    1211         state.style()->copyNonInheritedFrom(*cacheItem->renderStyle);
    1212         if (state.parentStyle()->inheritedDataShared(cacheItem->parentRenderStyle.get()) && !isAtShadowBoundary(element)) {
     1126        style.copyNonInheritedFrom(*cacheEntry->renderStyle);
     1127        if (parentStyle.inheritedDataShared(cacheEntry->parentRenderStyle.get()) && !isAtShadowBoundary(element)) {
    12131128            InsideLink linkStatus = state.style()->insideLink();
    12141129            // If the cache item parent style has identical inherited properties to the current parent style then the
    12151130            // resulting style will be identical too. We copy the inherited properties over from the cache and are done.
    1216             state.style()->inheritFrom(*cacheItem->renderStyle);
     1131            style.inheritFrom(*cacheEntry->renderStyle);
    12171132
    12181133            // Unfortunately the link status is treated like an inherited property. We need to explicitly restore it.
    1219             state.style()->setInsideLink(linkStatus);
     1134            style.setInsideLink(linkStatus);
    12201135            return;
    12211136        }
     
    12231138    }
    12241139
    1225     if (elementTypeHasAppearanceFromUAStyle(*state.element())) {
     1140    if (elementTypeHasAppearanceFromUAStyle(element)) {
    12261141        // FIXME: This is such a hack.
    12271142        // Find out if there's a -webkit-appearance property in effect from the UA sheet.
     
    12401155
    12411156    // If the effective zoom value changes, we can't use the matched properties cache. Start over.
    1242     if (cacheItem && cacheItem->renderStyle->effectiveZoom() != state.style()->effectiveZoom())
    1243         return applyMatchedProperties(matchResult, element, DoNotUseMatchedPropertiesCache);
     1157    if (cacheEntry && cacheEntry->renderStyle->effectiveZoom() != style.effectiveZoom())
     1158        return applyMatchedProperties(matchResult, element, UseMatchedDeclarationsCache::No);
    12441159
    12451160    // If the font changed, we can't use the matched properties cache. Start over.
    1246     if (cacheItem && cacheItem->renderStyle->fontDescription() != state.style()->fontDescription())
    1247         return applyMatchedProperties(matchResult, element, DoNotUseMatchedPropertiesCache);
     1161    if (cacheEntry && cacheEntry->renderStyle->fontDescription() != style.fontDescription())
     1162        return applyMatchedProperties(matchResult, element, UseMatchedDeclarationsCache::No);
    12481163
    12491164    builder.applyLowPriorityProperties();
     
    12521167        ruleSets().mutableFeatures().registerContentAttribute(contentAttribute);
    12531168
    1254     if (cacheItem || !cacheHash)
     1169    if (cacheEntry || !cacheHash)
    12551170        return;
    1256     if (!isCacheableInMatchedPropertiesCache(*state.element(), state.style(), state.parentStyle()))
    1257         return;
    1258     addToMatchedPropertiesCache(state.style(), state.parentStyle(), cacheHash, matchResult);
     1171
     1172    if (Style::MatchedDeclarationsCache::isCacheable(element, style, parentStyle))
     1173        m_matchedDeclarationsCache.add(style, parentStyle, cacheHash, matchResult);
    12591174}
    12601175
  • trunk/Source/WebCore/css/StyleResolver.h

    r251916 r252208  
    2626#include "ElementRuleCollector.h"
    2727#include "InspectorCSSOMWrappers.h"
     28#include "MatchedDeclarationsCache.h"
    2829#include "MediaQueryEvaluator.h"
    2930#include "RenderStyle.h"
    3031#include "RuleSet.h"
    31 #include "SelectorChecker.h"
    32 #include <bitset>
    3332#include <memory>
    34 #include <wtf/Bitmap.h>
    3533#include <wtf/HashMap.h>
    3634#include <wtf/RefPtr.h>
     
    182180    bool usesFirstLetterRules() const { return m_ruleSets.features().usesFirstLetterRules; }
    183181   
    184     void invalidateMatchedPropertiesCache();
    185 
    186     void clearCachedPropertiesAffectedByViewportUnits();
     182    void invalidateMatchedDeclarationsCache();
     183    void clearCachedDeclarationsAffectedByViewportUnits();
    187184
    188185private:
    189186    void adjustRenderStyle(RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element*);
    190187    void adjustRenderStyleForSiteSpecificQuirks(RenderStyle&, const Element&);
    191        
    192     enum ShouldUseMatchedPropertiesCache { DoNotUseMatchedPropertiesCache = 0, UseMatchedPropertiesCache };
    193     void applyMatchedProperties(const MatchResult&, const Element&, ShouldUseMatchedPropertiesCache = UseMatchedPropertiesCache);
     188
     189    enum class UseMatchedDeclarationsCache { Yes, No };
     190    void applyMatchedProperties(const MatchResult&, const Element&, UseMatchedDeclarationsCache = UseMatchedDeclarationsCache::Yes);
    194191
    195192    DocumentRuleSets m_ruleSets;
     
    253250    void cacheBorderAndBackground();
    254251
    255     static unsigned computeMatchedPropertiesHash(const MatchResult&);
    256     struct MatchedPropertiesCacheItem {
    257         Vector<MatchedProperties> userAgentDeclarations;
    258         Vector<MatchedProperties> userDeclarations;
    259         Vector<MatchedProperties> authorDeclarations;
    260         std::unique_ptr<RenderStyle> renderStyle;
    261         std::unique_ptr<RenderStyle> parentRenderStyle;
    262        
    263         MatchedPropertiesCacheItem(const MatchResult& matchResult, const RenderStyle* style, const RenderStyle* parentStyle)
    264             : renderStyle(RenderStyle::clonePtr(*style))
    265             , parentRenderStyle(RenderStyle::clonePtr(*parentStyle))
    266         {
    267             // Assign rather than copy-construct so we only allocate as much vector capacity as needed.
    268             userAgentDeclarations = matchResult.userAgentDeclarations;
    269             userDeclarations = matchResult.userDeclarations;
    270             authorDeclarations = matchResult.authorDeclarations;
    271         }
    272         MatchedPropertiesCacheItem() = default;
    273     };
    274     const MatchedPropertiesCacheItem* findFromMatchedPropertiesCache(unsigned hash, const MatchResult&);
    275     void addToMatchedPropertiesCache(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&);
    276 
    277     // Every N additions to the matched declaration cache trigger a sweep where entries holding
    278     // the last reference to a style declaration are garbage collected.
    279     void sweepMatchedPropertiesCache();
    280 
    281     typedef HashMap<unsigned, MatchedPropertiesCacheItem> MatchedPropertiesCache;
    282     MatchedPropertiesCache m_matchedPropertiesCache;
    283 
    284     Timer m_matchedPropertiesCacheSweepTimer;
    285 
    286252    MediaQueryEvaluator m_mediaQueryEvaluator;
    287253    std::unique_ptr<RenderStyle> m_rootDefaultStyle;
     
    303269    State m_state;
    304270
    305     unsigned m_matchedPropertiesCacheAdditionsSinceLastSweep { 0 };
     271    Style::MatchedDeclarationsCache m_matchedDeclarationsCache;
    306272
    307273    bool m_matchAuthorAndUserStyles { true };
  • trunk/Source/WebCore/dom/Document.cpp

    r252205 r252208  
    22912291{
    22922292    if (auto* resolver = styleScope().resolverIfExists())
    2293         resolver->invalidateMatchedPropertiesCache();
     2293        resolver->invalidateMatchedDeclarationsCache();
    22942294    if (backForwardCacheState() != NotInBackForwardCache || !renderView())
    22952295        return;
     
    39633963        return;
    39643964
    3965     styleScope().resolver().clearCachedPropertiesAffectedByViewportUnits();
     3965    styleScope().resolver().clearCachedDeclarationsAffectedByViewportUnits();
    39663966
    39673967    // FIXME: Ideally, we should save the list of elements that have viewport units and only iterate over those.
  • trunk/Source/WebCore/page/Page.cpp

    r252205 r252208  
    568568    forEachDocument([](Document& document) {
    569569        if (StyleResolver* styleResolver = document.styleScope().resolverIfExists())
    570             styleResolver->invalidateMatchedPropertiesCache();
     570            styleResolver->invalidateMatchedDeclarationsCache();
    571571        document.scheduleFullStyleRebuild();
    572572        document.styleScope().didChangeStyleSheetEnvironment();
  • trunk/Source/WebCore/style/StyleTreeResolver.cpp

    r251780 r252208  
    218218            // "rem" units are relative to the document element's font size so we need to recompute everything.
    219219            // In practice this is rare.
    220             scope().styleResolver.invalidateMatchedPropertiesCache();
     220            scope().styleResolver.invalidateMatchedDeclarationsCache();
    221221            descendantsToResolve = DescendantsToResolve::All;
    222222        }
Note: See TracChangeset for help on using the changeset viewer.