Title: [136956] trunk/Source/WebCore
- Revision
- 136956
- Author
- akl...@apple.com
- Date
- 2012-12-07 08:32:19 -0800 (Fri, 07 Dec 2012)
Log Message
Throw away StyleResolvers that haven't been used for a long time.
<http://webkit.org/b/104314>
Reviewed by Antti Koivisto.
A lot of memory gets tied up in StyleResolver and the structures and caches that hang from it.
Add a mechanism to throw it away after it's been unused for a while (1 minute.)
This frees up large amounts of memory on inactive pages (background tabs) and static content.
We already have a number of scenarios where the document style is invalidated by throwing away
the StyleResolver so the major code paths are prepared for having a null StyleResolver* on occasion.
~20MB progression on Membuster3.
* css/StyleResolver.cpp:
(WebCore::StyleResolver::styleForElement):
(WebCore::StyleResolver::styleForKeyframe):
(WebCore::StyleResolver::pseudoStyleForElement):
(WebCore::StyleResolver::styleForPage):
Call document()->didAccessStyleResolver() from the relevant parts of StyleResolver's public API.
This prevents Document from throwing the StyleResolver away for 1 minute after it's used.
* dom/Document.h:
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::createStyleResolver):
(WebCore::Document::didAccessStyleResolver):
(WebCore::Document::styleResolverThrowawayTimerFired):
Add a mechanism to call clearStyleResolver() on a refreshing timer.
* dom/Element.cpp:
(WebCore::Element::attributeChanged):
If an attribute change occurs while the document doesn't have a StyleResolver, dirty the element style
since we can't be sure that the attribute change didn't affect any rules.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (136955 => 136956)
--- trunk/Source/WebCore/ChangeLog 2012-12-07 16:09:10 UTC (rev 136955)
+++ trunk/Source/WebCore/ChangeLog 2012-12-07 16:32:19 UTC (rev 136956)
@@ -1,3 +1,43 @@
+2012-12-07 Andreas Kling <akl...@apple.com>
+
+ Throw away StyleResolvers that haven't been used for a long time.
+ <http://webkit.org/b/104314>
+
+ Reviewed by Antti Koivisto.
+
+ A lot of memory gets tied up in StyleResolver and the structures and caches that hang from it.
+ Add a mechanism to throw it away after it's been unused for a while (1 minute.)
+ This frees up large amounts of memory on inactive pages (background tabs) and static content.
+
+ We already have a number of scenarios where the document style is invalidated by throwing away
+ the StyleResolver so the major code paths are prepared for having a null StyleResolver* on occasion.
+
+ ~20MB progression on Membuster3.
+
+ * css/StyleResolver.cpp:
+ (WebCore::StyleResolver::styleForElement):
+ (WebCore::StyleResolver::styleForKeyframe):
+ (WebCore::StyleResolver::pseudoStyleForElement):
+ (WebCore::StyleResolver::styleForPage):
+
+ Call document()->didAccessStyleResolver() from the relevant parts of StyleResolver's public API.
+ This prevents Document from throwing the StyleResolver away for 1 minute after it's used.
+
+ * dom/Document.h:
+ * dom/Document.cpp:
+ (WebCore::Document::Document):
+ (WebCore::Document::createStyleResolver):
+ (WebCore::Document::didAccessStyleResolver):
+ (WebCore::Document::styleResolverThrowawayTimerFired):
+
+ Add a mechanism to call clearStyleResolver() on a refreshing timer.
+
+ * dom/Element.cpp:
+ (WebCore::Element::attributeChanged):
+
+ If an attribute change occurs while the document doesn't have a StyleResolver, dirty the element style
+ since we can't be sure that the attribute change didn't affect any rules.
+
2012-12-07 Antonio Gomes <a1.go...@sisa.samsung.com>
REGRESSION(r136947): Made two tests fail on all platforms (Requested by tonikitoo-ll on #webkit).
Modified: trunk/Source/WebCore/css/StyleResolver.cpp (136955 => 136956)
--- trunk/Source/WebCore/css/StyleResolver.cpp 2012-12-07 16:09:10 UTC (rev 136955)
+++ trunk/Source/WebCore/css/StyleResolver.cpp 2012-12-07 16:32:19 UTC (rev 136956)
@@ -1601,6 +1601,8 @@
if (cloneForParent)
m_parentStyle = 0;
+ document()->didAccessStyleResolver();
+
// Now return the style.
return m_style.release();
}
@@ -1654,6 +1656,8 @@
}
}
+ document()->didAccessStyleResolver();
+
return m_style.release();
}
@@ -1757,6 +1761,8 @@
// Start loading resources referenced by this style.
loadPendingResources();
+ document()->didAccessStyleResolver();
+
// Now return the style.
return m_style.release();
}
@@ -1796,6 +1802,8 @@
// Start loading resources referenced by this style.
loadPendingResources();
+ document()->didAccessStyleResolver();
+
// Now return the style.
return m_style.release();
}
Modified: trunk/Source/WebCore/dom/Document.cpp (136955 => 136956)
--- trunk/Source/WebCore/dom/Document.cpp 2012-12-07 16:09:10 UTC (rev 136955)
+++ trunk/Source/WebCore/dom/Document.cpp 2012-12-07 16:32:19 UTC (rev 136956)
@@ -437,6 +437,8 @@
: ContainerNode(0, CreateDocument)
, TreeScope(this)
, m_guardRefCount(0)
+ , m_styleResolverThrowawayTimer(this, &Document::styleResolverThrowawayTimerFired)
+ , m_lastStyleResolverAccessTime(0)
, m_contextFeatures(ContextFeatures::defaultSwitch())
, m_compatibilityMode(NoQuirksMode)
, m_compatibilityModeLocked(false)
@@ -4433,6 +4435,24 @@
m_sharedObjectPool.clear();
}
+void Document::didAccessStyleResolver()
+{
+ static const int timeBeforeThrowingAwayStyleResolverAfterLastUseInSeconds = 60;
+ static const int holdOffTimeBeforeReschedulingTimerInSeconds = 5;
+
+ double currentTime = WTF::currentTime();
+
+ if (currentTime > m_lastStyleResolverAccessTime + holdOffTimeBeforeReschedulingTimerInSeconds) {
+ m_styleResolverThrowawayTimer.startOneShot(timeBeforeThrowingAwayStyleResolverAfterLastUseInSeconds);
+ m_lastStyleResolverAccessTime = currentTime;
+ }
+}
+
+void Document::styleResolverThrowawayTimerFired(Timer<Document>*)
+{
+ clearStyleResolver();
+}
+
PassRefPtr<XPathExpression> Document::createExpression(const String& _expression_,
XPathNSResolver* resolver,
ExceptionCode& ec)
Modified: trunk/Source/WebCore/dom/Document.h (136955 => 136956)
--- trunk/Source/WebCore/dom/Document.h 2012-12-07 16:09:10 UTC (rev 136955)
+++ trunk/Source/WebCore/dom/Document.h 2012-12-07 16:32:19 UTC (rev 136956)
@@ -496,6 +496,8 @@
*/
void styleResolverChanged(StyleResolverUpdateFlag);
+ void didAccessStyleResolver();
+
void evaluateMediaQueryList();
// Never returns 0.
@@ -1260,6 +1262,10 @@
int m_guardRefCount;
+ void styleResolverThrowawayTimerFired(Timer<Document>*);
+ Timer<Document> m_styleResolverThrowawayTimer;
+ double m_lastStyleResolverAccessTime;
+
OwnPtr<StyleResolver> m_styleResolver;
bool m_didCalculateStyleResolver;
bool m_hasDirtyStyleResolver;
Modified: trunk/Source/WebCore/dom/Element.cpp (136955 => 136956)
--- trunk/Source/WebCore/dom/Element.cpp 2012-12-07 16:09:10 UTC (rev 136955)
+++ trunk/Source/WebCore/dom/Element.cpp 2012-12-07 16:32:19 UTC (rev 136956)
@@ -799,6 +799,9 @@
invalidateNodeListCachesInAncestors(&name, this);
+ // If there is currently no StyleResolver, we can't be sure that this attribute change won't affect style.
+ shouldInvalidateStyle |= !styleResolver;
+
if (shouldInvalidateStyle)
setNeedsStyleRecalc();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes