Optimize Style::determineChange()
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Feb 2020 17:57:04 +0000 (17:57 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 9 Feb 2020 17:57:04 +0000 (17:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=207438

Reviewed by Antti Koivisto.

Style::determineChange() called RenderStyle::operator!=() before the testing some other
sets of properties for inequality.

It's faster to call inheritedEqual() etc before the full style compare. Also optimize
comparing alignItems() and justifyItems() by adding a helper function that first tests
for equality of the m_rareNonInheritedData pointer. These (added in r213480) return Inherit
because align-items and justify-items affect child layout.

This is a ~4% progression on some MotionMark subtests. Time under TreeResolver::createAnimatedElementUpdate()
drops from 2.4% to 0.9%.

* rendering/style/RenderStyle.cpp:
(WebCore::RenderStyle::descendantAffectingNonInheritedPropertiesEqual const):
* rendering/style/RenderStyle.h:
* style/StyleChange.cpp:
(WebCore::Style::determineChange):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@256102 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/style/RenderStyle.cpp
Source/WebCore/rendering/style/RenderStyle.h
Source/WebCore/style/StyleChange.cpp

index 89053eb..fb5b20f 100644 (file)
@@ -1,3 +1,27 @@
+2020-02-08  Simon Fraser  <simon.fraser@apple.com>
+
+        Optimize Style::determineChange()
+        https://bugs.webkit.org/show_bug.cgi?id=207438
+
+        Reviewed by Antti Koivisto.
+
+        Style::determineChange() called RenderStyle::operator!=() before the testing some other
+        sets of properties for inequality.
+        
+        It's faster to call inheritedEqual() etc before the full style compare. Also optimize
+        comparing alignItems() and justifyItems() by adding a helper function that first tests
+        for equality of the m_rareNonInheritedData pointer. These (added in r213480) return Inherit
+        because align-items and justify-items affect child layout.
+        
+        This is a ~4% progression on some MotionMark subtests. Time under TreeResolver::createAnimatedElementUpdate()
+        drops from 2.4% to 0.9%.
+
+        * rendering/style/RenderStyle.cpp:
+        (WebCore::RenderStyle::descendantAffectingNonInheritedPropertiesEqual const):
+        * rendering/style/RenderStyle.h:
+        * style/StyleChange.cpp:
+        (WebCore::Style::determineChange):
+
 2020-02-09  Zalan Bujtas  <zalan@apple.com>
 
         [LFC] FloatingContext::constraints should take a vertical range instead of just vertical position.
index 9fa65fb..9054200 100644 (file)
@@ -438,6 +438,15 @@ bool RenderStyle::inheritedEqual(const RenderStyle& other) const
         && m_rareInheritedData == other.m_rareInheritedData;
 }
 
+bool RenderStyle::descendantAffectingNonInheritedPropertiesEqual(const RenderStyle& other) const
+{
+    if (m_rareNonInheritedData.ptr() == other.m_rareNonInheritedData.ptr())
+        return true;
+    
+    return m_rareNonInheritedData->alignItems == other.m_rareNonInheritedData->alignItems
+        && m_rareNonInheritedData->justifyItems == other.m_rareNonInheritedData->justifyItems;
+}
+
 #if ENABLE(TEXT_AUTOSIZING)
 
 static inline unsigned computeFontHash(const FontCascade& font)
index 31d294c..d46cdf6 100644 (file)
@@ -1418,6 +1418,7 @@ public:
     const AtomString& hyphenString() const;
 
     bool inheritedEqual(const RenderStyle&) const;
+    bool descendantAffectingNonInheritedPropertiesEqual(const RenderStyle&) const;
 
 #if ENABLE(TEXT_AUTOSIZING)
     uint32_t hashForTextAutosizing() const;
index 22adae7..31ef165 100644 (file)
@@ -49,15 +49,14 @@ Change determineChange(const RenderStyle& s1, const RenderStyle& s2)
     if (s1.hasTextCombine() != s2.hasTextCombine())
         return Detach;
 
-    if (s1 != s2) {
-        if (!s1.inheritedEqual(s2))
-            return Inherit;
+    if (!s1.inheritedEqual(s2))
+        return Inherit;
 
-        if (s1.alignItems() != s2.alignItems() || s1.justifyItems() != s2.justifyItems())
-            return Inherit;
+    if (!s1.descendantAffectingNonInheritedPropertiesEqual(s2))
+        return Inherit;
 
+    if (s1 != s2)
         return NoInherit;
-    }
 
     // If the pseudoStyles have changed, we want any StyleChange that is not NoChange
     // because setStyle will do the right thing with anything else.