Title: [291790] trunk/Source/WebCore
Revision
291790
Author
an...@apple.com
Date
2022-03-24 05:18:54 -0700 (Thu, 24 Mar 2022)

Log Message

Allow styles with appearance in matched declaration cache
https://bugs.webkit.org/show_bug.cgi?id=238247

Reviewed by Antoine Quint.

Improve cache efficiency by allowing styles with appearance (typically form controls) to be cached.

In Speedometer this improves the cache hit rate ~75% -> 94%.

* style/MatchedDeclarationsCache.cpp:
(WebCore::Style::MatchedDeclarationsCache::isCacheable):

Remove appearance check.

(WebCore::Style::MatchedDeclarationsCache::add):

Also cache the UA style for styles with appearance.

(WebCore::Style::MatchedDeclarationsCache::remove):
* style/MatchedDeclarationsCache.h:
* style/StyleResolver.cpp:
(WebCore::Style::Resolver::applyMatchedProperties):

Also simplify the case where inherited properties affect resolution of other properties by
kicking out the existing entry. This also makes the second attempt cacheable.

* style/StyleResolver.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (291789 => 291790)


--- trunk/Source/WebCore/ChangeLog	2022-03-24 08:33:41 UTC (rev 291789)
+++ trunk/Source/WebCore/ChangeLog	2022-03-24 12:18:54 UTC (rev 291790)
@@ -1,3 +1,33 @@
+2022-03-24  Antti Koivisto  <an...@apple.com>
+
+        Allow styles with appearance in matched declaration cache
+        https://bugs.webkit.org/show_bug.cgi?id=238247
+
+        Reviewed by Antoine Quint.
+
+        Improve cache efficiency by allowing styles with appearance (typically form controls) to be cached.
+
+        In Speedometer this improves the cache hit rate ~75% -> 94%.
+
+        * style/MatchedDeclarationsCache.cpp:
+        (WebCore::Style::MatchedDeclarationsCache::isCacheable):
+
+        Remove appearance check.
+
+        (WebCore::Style::MatchedDeclarationsCache::add):
+
+        Also cache the UA style for styles with appearance.
+
+        (WebCore::Style::MatchedDeclarationsCache::remove):
+        * style/MatchedDeclarationsCache.h:
+        * style/StyleResolver.cpp:
+        (WebCore::Style::Resolver::applyMatchedProperties):
+
+        Also simplify the case where inherited properties affect resolution of other properties by
+        kicking out the existing entry. This also makes the second attempt cacheable.
+
+        * style/StyleResolver.h:
+
 2022-03-09  Sergio Villar Senin  <svil...@igalia.com>
 
         Release assert in Document::updateLayout() via HTMLTextAreaElement::childrenChanged

Modified: trunk/Source/WebCore/style/MatchedDeclarationsCache.cpp (291789 => 291790)


--- trunk/Source/WebCore/style/MatchedDeclarationsCache.cpp	2022-03-24 08:33:41 UTC (rev 291789)
+++ trunk/Source/WebCore/style/MatchedDeclarationsCache.cpp	2022-03-24 12:18:54 UTC (rev 291790)
@@ -54,8 +54,6 @@
     // content:attr() value depends on the element it is being applied to.
     if (style.hasAttrContent() || (style.styleType() != PseudoId::None && parentStyle.hasAttrContent()))
         return false;
-    if (style.hasEffectiveAppearance())
-        return false;
     if (style.zoom() != RenderStyle::initialZoom())
         return false;
     if (style.writingMode() != RenderStyle::initialWritingMode() || style.direction() != RenderStyle::initialDirection())
@@ -107,7 +105,7 @@
     return &entry;
 }
 
-void MatchedDeclarationsCache::add(const RenderStyle& style, const RenderStyle& parentStyle, unsigned hash, const MatchResult& matchResult)
+void MatchedDeclarationsCache::add(const RenderStyle& style, const RenderStyle& parentStyle, const RenderStyle* userAgentAppearanceStyle, unsigned hash, const MatchResult& matchResult)
 {
     constexpr unsigned additionsBetweenSweeps = 100;
     if (++m_additionsSinceLastSweep >= additionsBetweenSweeps && !m_sweepTimer.isActive()) {
@@ -115,12 +113,23 @@
         m_sweepTimer.startOneShot(sweepDelay);
     }
 
+    auto userAgentAppearanceStyleCopy = [&]() -> std::unique_ptr<RenderStyle> {
+        if (userAgentAppearanceStyle)
+            return RenderStyle::clonePtr(*userAgentAppearanceStyle);
+        return { };
+    };
+
     ASSERT(hash);
     // Note that we don't cache the original RenderStyle instance. It may be further modified.
     // The RenderStyle in the cache is really just a holder for the substructures and never used as-is.
-    m_entries.add(hash, Entry { matchResult, RenderStyle::clonePtr(style), RenderStyle::clonePtr(parentStyle) });
+    m_entries.add(hash, Entry { matchResult, RenderStyle::clonePtr(style), RenderStyle::clonePtr(parentStyle), userAgentAppearanceStyleCopy() });
 }
 
+void MatchedDeclarationsCache::remove(unsigned hash)
+{
+    m_entries.remove(hash);
+}
+
 void MatchedDeclarationsCache::invalidate()
 {
     m_entries.clear();

Modified: trunk/Source/WebCore/style/MatchedDeclarationsCache.h (291789 => 291790)


--- trunk/Source/WebCore/style/MatchedDeclarationsCache.h	2022-03-24 08:33:41 UTC (rev 291789)
+++ trunk/Source/WebCore/style/MatchedDeclarationsCache.h	2022-03-24 12:18:54 UTC (rev 291790)
@@ -46,12 +46,14 @@
         MatchResult matchResult;
         std::unique_ptr<const RenderStyle> renderStyle;
         std::unique_ptr<const RenderStyle> parentRenderStyle;
+        std::unique_ptr<const RenderStyle> userAgentAppearanceStyle;
 
         bool isUsableAfterHighPriorityProperties(const RenderStyle&) const;
     };
 
     const Entry* find(unsigned hash, const MatchResult&);
-    void add(const RenderStyle&, const RenderStyle& parentStyle, unsigned hash, const MatchResult&);
+    void add(const RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* userAgentAppearanceStyle, unsigned hash, const MatchResult&);
+    void remove(unsigned hash);
 
     // Every N additions to the matched declaration cache trigger a sweep where entries holding
     // the last reference to a style declaration are garbage collected.

Modified: trunk/Source/WebCore/style/StyleResolver.cpp (291789 => 291790)


--- trunk/Source/WebCore/style/StyleResolver.cpp	2022-03-24 08:33:41 UTC (rev 291789)
+++ trunk/Source/WebCore/style/StyleResolver.cpp	2022-03-24 12:18:54 UTC (rev 291790)
@@ -571,9 +571,9 @@
     m_matchedDeclarationsCache.clearEntriesAffectedByViewportUnits();
 }
 
-void Resolver::applyMatchedProperties(State& state, const MatchResult& matchResult, UseMatchedDeclarationsCache useMatchedDeclarationsCache)
+void Resolver::applyMatchedProperties(State& state, const MatchResult& matchResult)
 {
-    unsigned cacheHash = useMatchedDeclarationsCache == UseMatchedDeclarationsCache::Yes ? MatchedDeclarationsCache::computeHash(matchResult) : 0;
+    unsigned cacheHash = MatchedDeclarationsCache::computeHash(matchResult);
     auto includedProperties = PropertyCascade::IncludedProperties::All;
 
     auto& style = *state.style();
@@ -595,9 +595,13 @@
 
             // Unfortunately the link status is treated like an inherited property. We need to explicitly restore it.
             style.setInsideLink(linkStatus);
+
+            if (cacheEntry->userAgentAppearanceStyle && elementTypeHasAppearanceFromUAStyle(element))
+                state.setUserAgentAppearanceStyle(RenderStyle::clonePtr(*cacheEntry->userAgentAppearanceStyle));
+
             return;
         }
-        
+
         includedProperties = PropertyCascade::IncludedProperties::InheritedOnly;
     }
 
@@ -618,8 +622,9 @@
     builder.applyHighPriorityProperties();
 
     if (cacheEntry && !cacheEntry->isUsableAfterHighPriorityProperties(style)) {
-        // We need to resolve all properties without caching.
-        applyMatchedProperties(state, matchResult, UseMatchedDeclarationsCache::No);
+        // High-priority properties may affect resolution of other properties. Kick out the existing cache entry and try again.
+        m_matchedDeclarationsCache.remove(cacheHash);
+        applyMatchedProperties(state, matchResult);
         return;
     }
 
@@ -632,7 +637,7 @@
         return;
 
     if (MatchedDeclarationsCache::isCacheable(element, style, parentStyle))
-        m_matchedDeclarationsCache.add(style, parentStyle, cacheHash, matchResult);
+        m_matchedDeclarationsCache.add(style, parentStyle, state.userAgentAppearanceStyle(), cacheHash, matchResult);
 }
 
 bool Resolver::hasViewportDependentMediaQueries() const

Modified: trunk/Source/WebCore/style/StyleResolver.h (291789 => 291790)


--- trunk/Source/WebCore/style/StyleResolver.h	2022-03-24 08:33:41 UTC (rev 291789)
+++ trunk/Source/WebCore/style/StyleResolver.h	2022-03-24 12:18:54 UTC (rev 291790)
@@ -159,8 +159,7 @@
 
     BuilderContext builderContext(const State&);
 
-    enum class UseMatchedDeclarationsCache { Yes, No };
-    void applyMatchedProperties(State&, const MatchResult&, UseMatchedDeclarationsCache = UseMatchedDeclarationsCache::Yes);
+    void applyMatchedProperties(State&, const MatchResult&);
 
     ScopeRuleSets m_ruleSets;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to