Modified: trunk/Source/WebCore/ChangeLog (210825 => 210826)
--- trunk/Source/WebCore/ChangeLog 2017-01-17 20:57:53 UTC (rev 210825)
+++ trunk/Source/WebCore/ChangeLog 2017-01-17 23:24:46 UTC (rev 210826)
@@ -1,3 +1,29 @@
+2017-01-17 Andreas Kling <[email protected]>
+
+ Kill the presentation attribute cache.
+ <https://webkit.org/b/119542>
+
+ Reviewed by Antti Koivisto.
+
+ This cache was added to placate some old page cycler test that was measuring load times
+ on pages captured in 2000. That content is not super relevant anymore, and I think
+ we can live without this cache.
+
+ * dom/StyledElement.cpp:
+ (WebCore::StyledElement::rebuildPresentationAttributeStyle):
+ (WebCore::presentationAttributeCache): Deleted.
+ (WebCore::PresentationAttributeCacheCleaner::PresentationAttributeCacheCleaner): Deleted.
+ (WebCore::PresentationAttributeCacheCleaner::didHitPresentationAttributeCache): Deleted.
+ (WebCore::PresentationAttributeCacheCleaner::cleanCache): Deleted.
+ (WebCore::presentationAttributeCacheCleaner): Deleted.
+ (WebCore::StyledElement::clearPresentationAttributeCache): Deleted.
+ (WebCore::attributeNameSort): Deleted.
+ (WebCore::StyledElement::makePresentationAttributeCacheKey): Deleted.
+ (WebCore::computePresentationAttributeCacheHash): Deleted.
+ * dom/StyledElement.h:
+ * page/MemoryRelease.cpp:
+ (WebCore::releaseNoncriticalMemory):
+
2017-01-17 Filip Pizlo <[email protected]>
Unreviewed, roll out http://trac.webkit.org/changeset/210821
Modified: trunk/Source/WebCore/dom/StyledElement.cpp (210825 => 210826)
--- trunk/Source/WebCore/dom/StyledElement.cpp 2017-01-17 20:57:53 UTC (rev 210825)
+++ trunk/Source/WebCore/dom/StyledElement.cpp 2017-01-17 23:24:46 UTC (rev 210826)
@@ -46,83 +46,6 @@
using namespace HTMLNames;
-struct PresentationAttributeCacheKey {
- AtomicStringImpl* tagName { nullptr };
- // Only the values need refcounting.
- Vector<std::pair<AtomicStringImpl*, AtomicString>, 3> attributesAndValues;
-};
-
-struct PresentationAttributeCacheEntry {
- WTF_MAKE_FAST_ALLOCATED;
-public:
- PresentationAttributeCacheKey key;
- RefPtr<StyleProperties> value;
-};
-
-typedef HashMap<unsigned, std::unique_ptr<PresentationAttributeCacheEntry>, AlreadyHashed> PresentationAttributeCache;
-
-static bool operator!=(const PresentationAttributeCacheKey& a, const PresentationAttributeCacheKey& b)
-{
- if (a.tagName != b.tagName)
- return true;
- return a.attributesAndValues != b.attributesAndValues;
-}
-
-static PresentationAttributeCache& presentationAttributeCache()
-{
- static NeverDestroyed<PresentationAttributeCache> cache;
- return cache;
-}
-
-class PresentationAttributeCacheCleaner {
- WTF_MAKE_NONCOPYABLE(PresentationAttributeCacheCleaner); WTF_MAKE_FAST_ALLOCATED;
-public:
- PresentationAttributeCacheCleaner()
- : m_hitCount(0)
- , m_cleanTimer(*this, &PresentationAttributeCacheCleaner::cleanCache)
- {
- }
-
- void didHitPresentationAttributeCache()
- {
- if (presentationAttributeCache().size() < minimumPresentationAttributeCacheSizeForCleaning)
- return;
-
- m_hitCount++;
-
- if (!m_cleanTimer.isActive())
- m_cleanTimer.startOneShot(presentationAttributeCacheCleanTimeInSeconds);
- }
-
-private:
- static const unsigned presentationAttributeCacheCleanTimeInSeconds = 60;
- static const int minimumPresentationAttributeCacheSizeForCleaning = 100;
- static const unsigned minimumPresentationAttributeCacheHitCountPerMinute = (100 * presentationAttributeCacheCleanTimeInSeconds) / 60;
-
- void cleanCache()
- {
- unsigned hitCount = m_hitCount;
- m_hitCount = 0;
- if (hitCount > minimumPresentationAttributeCacheHitCountPerMinute)
- return;
- presentationAttributeCache().clear();
- }
-
- unsigned m_hitCount;
- Timer m_cleanTimer;
-};
-
-static PresentationAttributeCacheCleaner& presentationAttributeCacheCleaner()
-{
- static NeverDestroyed<PresentationAttributeCacheCleaner> cleaner;
- return cleaner;
-}
-
-void StyledElement::clearPresentationAttributeCache()
-{
- presentationAttributeCache().clear();
-}
-
void StyledElement::synchronizeStyleAttributeInternal(StyledElement* styledElement)
{
ASSERT(styledElement->elementData());
@@ -295,92 +218,17 @@
});
}
-static inline bool attributeNameSort(const std::pair<AtomicStringImpl*, AtomicString>& p1, const std::pair<AtomicStringImpl*, AtomicString>& p2)
-{
- // Sort based on the attribute name pointers. It doesn't matter what the order is as long as it is always the same.
- return p1.first < p2.first;
-}
-
-void StyledElement::makePresentationAttributeCacheKey(PresentationAttributeCacheKey& result) const
-{
- // FIXME: Enable for SVG.
- if (namespaceURI() != xhtmlNamespaceURI)
- return;
- // Interpretation of the size attributes on <input> depends on the type attribute.
- if (hasTagName(inputTag))
- return;
- for (const Attribute& attribute : attributesIterator()) {
- if (!isPresentationAttribute(attribute.name()))
- continue;
- if (!attribute.namespaceURI().isNull())
- return;
- // FIXME: Background URL may depend on the base URL and can't be shared. Disallow caching.
- if (attribute.name() == backgroundAttr)
- return;
- result.attributesAndValues.append(std::make_pair(attribute.localName().impl(), attribute.value()));
- }
- if (result.attributesAndValues.isEmpty())
- return;
- // Attribute order doesn't matter. Sort for easy equality comparison.
- std::sort(result.attributesAndValues.begin(), result.attributesAndValues.end(), attributeNameSort);
- // The cache key is non-null when the tagName is set.
- result.tagName = localName().impl();
-}
-
-static unsigned computePresentationAttributeCacheHash(const PresentationAttributeCacheKey& key)
-{
- if (!key.tagName)
- return 0;
- ASSERT(key.attributesAndValues.size());
- unsigned attributeHash = StringHasher::hashMemory(key.attributesAndValues.data(), key.attributesAndValues.size() * sizeof(key.attributesAndValues[0]));
- return WTF::pairIntHash(key.tagName->existingHash(), attributeHash);
-}
-
void StyledElement::rebuildPresentationAttributeStyle()
{
- PresentationAttributeCacheKey cacheKey;
- makePresentationAttributeCacheKey(cacheKey);
+ RefPtr<StyleProperties> style = MutableStyleProperties::create(isSVGElement() ? SVGAttributeMode : HTMLQuirksMode);
+ for (const Attribute& attribute : attributesIterator())
+ collectStyleForPresentationAttribute(attribute.name(), attribute.value(), static_cast<MutableStyleProperties&>(*style));
- unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey);
-
- PresentationAttributeCache::iterator cacheIterator;
- if (cacheHash) {
- cacheIterator = presentationAttributeCache().add(cacheHash, nullptr).iterator;
- if (cacheIterator->value && cacheIterator->value->key != cacheKey)
- cacheHash = 0;
- } else
- cacheIterator = presentationAttributeCache().end();
-
- RefPtr<StyleProperties> style;
- if (cacheHash && cacheIterator->value) {
- style = cacheIterator->value->value;
- presentationAttributeCacheCleaner().didHitPresentationAttributeCache();
- } else {
- style = MutableStyleProperties::create(isSVGElement() ? SVGAttributeMode : HTMLQuirksMode);
- for (const Attribute& attribute : attributesIterator())
- collectStyleForPresentationAttribute(attribute.name(), attribute.value(), static_cast<MutableStyleProperties&>(*style));
- }
-
// ShareableElementData doesn't store presentation attribute style, so make sure we have a UniqueElementData.
UniqueElementData& elementData = ensureUniqueElementData();
elementData.setPresentationAttributeStyleIsDirty(false);
- elementData.m_presentationAttributeStyle = style->isEmpty() ? nullptr : style;
-
- if (!cacheHash || cacheIterator->value)
- return;
-
- std::unique_ptr<PresentationAttributeCacheEntry> newEntry = std::make_unique<PresentationAttributeCacheEntry>();
- newEntry->key = cacheKey;
- newEntry->value = WTFMove(style);
-
- static const int presentationAttributeCacheMaximumSize = 4096;
- if (presentationAttributeCache().size() > presentationAttributeCacheMaximumSize) {
- // Start building from scratch if the cache ever gets big.
- presentationAttributeCache().clear();
- presentationAttributeCache().set(cacheHash, WTFMove(newEntry));
- } else
- cacheIterator->value = WTFMove(newEntry);
+ elementData.m_presentationAttributeStyle = style->isEmpty() ? nullptr : WTFMove(style);
}
void StyledElement::addPropertyToPresentationAttributeStyle(MutableStyleProperties& style, CSSPropertyID propertyID, CSSValueID identifier)
Modified: trunk/Source/WebCore/dom/StyledElement.h (210825 => 210826)
--- trunk/Source/WebCore/dom/StyledElement.h 2017-01-17 20:57:53 UTC (rev 210825)
+++ trunk/Source/WebCore/dom/StyledElement.h 2017-01-17 23:24:46 UTC (rev 210826)
@@ -36,8 +36,6 @@
class PropertySetCSSStyleDeclaration;
class StyleProperties;
-struct PresentationAttributeCacheKey;
-
class StyledElement : public Element {
public:
virtual ~StyledElement();
@@ -62,8 +60,6 @@
const StyleProperties* presentationAttributeStyle() const;
virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStyleProperties&) { }
- static void clearPresentationAttributeCache();
-
protected:
StyledElement(const QualifiedName& name, Document& document, ConstructionType type)
: Element(name, document, type)
@@ -88,7 +84,6 @@
void setInlineStyleFromString(const AtomicString&);
MutableStyleProperties& ensureMutableInlineStyle();
- void makePresentationAttributeCacheKey(PresentationAttributeCacheKey&) const;
void rebuildPresentationAttributeStyle();
};
Modified: trunk/Source/WebCore/page/MemoryRelease.cpp (210825 => 210826)
--- trunk/Source/WebCore/page/MemoryRelease.cpp 2017-01-17 20:57:53 UTC (rev 210825)
+++ trunk/Source/WebCore/page/MemoryRelease.cpp 2017-01-17 23:24:46 UTC (rev 210826)
@@ -60,8 +60,6 @@
MemoryCache::singleton().pruneDeadResourcesToSize(0);
- StyledElement::clearPresentationAttributeCache();
-
InlineStyleSheetOwner::clearCache();
}