Title: [153699] trunk/Source/WebCore
- Revision
- 153699
- Author
- [email protected]
- Date
- 2013-08-04 08:57:13 -0700 (Sun, 04 Aug 2013)
Log Message
Inserting a rule into an empty style sheet shouldn't trigger style recalc unless necessary.
<http://webkit.org/b/119475>
<rdar://problem/14643481>
Reviewed by Antti Koivisto.
This is kind of a cheesy optimization, but it turns out that the use case is quite common.
The pattern goes like this:
(1) Create <style> element.
(2) Add it to the document's <head>.
(3) .addRule() one rule through the CSSOM API.
Prior to this patch, (3) would always cause a full (deferred) style recalc.
Now that we exclude empty style sheets from the document's (effective) active set,
we can piggyback on the style invalidation analysis when transitioning from an empty
sheet to a single-rule sheet.
In other words, add a special code path for the first rule insertion into an empty,
in-document style sheet to minimize the amount of invalidation that happens.
* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::didMutateRules):
(WebCore::CSSStyleSheet::insertRule):
* css/CSSStyleSheet.h:
(WebCore::CSSStyleSheet::RuleMutationScope::RuleMutationScope):
(WebCore::CSSStyleSheet::RuleMutationScope::~RuleMutationScope):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (153698 => 153699)
--- trunk/Source/WebCore/ChangeLog 2013-08-04 14:35:34 UTC (rev 153698)
+++ trunk/Source/WebCore/ChangeLog 2013-08-04 15:57:13 UTC (rev 153699)
@@ -1,3 +1,34 @@
+2013-08-04 Andreas Kling <[email protected]>
+
+ Inserting a rule into an empty style sheet shouldn't trigger style recalc unless necessary.
+ <http://webkit.org/b/119475>
+ <rdar://problem/14643481>
+
+ Reviewed by Antti Koivisto.
+
+ This is kind of a cheesy optimization, but it turns out that the use case is quite common.
+ The pattern goes like this:
+
+ (1) Create <style> element.
+ (2) Add it to the document's <head>.
+ (3) .addRule() one rule through the CSSOM API.
+
+ Prior to this patch, (3) would always cause a full (deferred) style recalc.
+
+ Now that we exclude empty style sheets from the document's (effective) active set,
+ we can piggyback on the style invalidation analysis when transitioning from an empty
+ sheet to a single-rule sheet.
+
+ In other words, add a special code path for the first rule insertion into an empty,
+ in-document style sheet to minimize the amount of invalidation that happens.
+
+ * css/CSSStyleSheet.cpp:
+ (WebCore::CSSStyleSheet::didMutateRules):
+ (WebCore::CSSStyleSheet::insertRule):
+ * css/CSSStyleSheet.h:
+ (WebCore::CSSStyleSheet::RuleMutationScope::RuleMutationScope):
+ (WebCore::CSSStyleSheet::RuleMutationScope::~RuleMutationScope):
+
2013-08-04 Claudio Saavedra <[email protected]>
[GTK] Fix a C++11 warning.
Modified: trunk/Source/WebCore/css/CSSStyleSheet.cpp (153698 => 153699)
--- trunk/Source/WebCore/css/CSSStyleSheet.cpp 2013-08-04 14:35:34 UTC (rev 153698)
+++ trunk/Source/WebCore/css/CSSStyleSheet.cpp 2013-08-04 15:57:13 UTC (rev 153699)
@@ -147,12 +147,15 @@
reattachChildRuleCSSOMWrappers();
}
-void CSSStyleSheet::didMutateRules()
+void CSSStyleSheet::didMutateRules(RuleMutationType mutationType)
{
ASSERT(m_contents->isMutable());
ASSERT(m_contents->hasOneClient());
- didMutate();
+ Document* owner = ownerDocument();
+ if (!owner)
+ return;
+ owner->styleResolverChanged(mutationType == InsertionIntoEmptySheet ? DeferRecalcStyleIfNeeded : DeferRecalcStyle);
}
void CSSStyleSheet::didMutate()
@@ -275,8 +278,10 @@
ec = SYNTAX_ERR;
return 0;
}
- RuleMutationScope mutationScope(this);
+ RuleMutationType mutationType = !length() ? InsertionIntoEmptySheet : OtherMutation;
+ RuleMutationScope mutationScope(this, mutationType);
+
bool success = m_contents->wrapperInsertRule(rule, index);
if (!success) {
ec = HIERARCHY_REQUEST_ERR;
Modified: trunk/Source/WebCore/css/CSSStyleSheet.h (153698 => 153699)
--- trunk/Source/WebCore/css/CSSStyleSheet.h 2013-08-04 14:35:34 UTC (rev 153698)
+++ trunk/Source/WebCore/css/CSSStyleSheet.h 2013-08-04 15:57:13 UTC (rev 153699)
@@ -85,19 +85,22 @@
void setMediaQueries(PassRefPtr<MediaQuerySet>);
void setTitle(const String& title) { m_title = title; }
+ enum RuleMutationType { OtherMutation, InsertionIntoEmptySheet };
+
class RuleMutationScope {
WTF_MAKE_NONCOPYABLE(RuleMutationScope);
public:
- RuleMutationScope(CSSStyleSheet*);
+ RuleMutationScope(CSSStyleSheet*, RuleMutationType = OtherMutation);
RuleMutationScope(CSSRule*);
~RuleMutationScope();
private:
CSSStyleSheet* m_styleSheet;
+ RuleMutationType m_mutationType;
};
void willMutateRules();
- void didMutateRules();
+ void didMutateRules(RuleMutationType = OtherMutation);
void didMutate();
void clearChildRuleCSSOMWrappers();
@@ -128,8 +131,9 @@
mutable OwnPtr<CSSRuleList> m_ruleListCSSOMWrapper;
};
-inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet)
+inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSStyleSheet* sheet, RuleMutationType mutationType)
: m_styleSheet(sheet)
+ , m_mutationType(mutationType)
{
if (m_styleSheet)
m_styleSheet->willMutateRules();
@@ -137,6 +141,7 @@
inline CSSStyleSheet::RuleMutationScope::RuleMutationScope(CSSRule* rule)
: m_styleSheet(rule ? rule->parentStyleSheet() : 0)
+ , m_mutationType(OtherMutation)
{
if (m_styleSheet)
m_styleSheet->willMutateRules();
@@ -145,7 +150,7 @@
inline CSSStyleSheet::RuleMutationScope::~RuleMutationScope()
{
if (m_styleSheet)
- m_styleSheet->didMutateRules();
+ m_styleSheet->didMutateRules(m_mutationType);
}
} // namespace
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes