Title: [237463] trunk/Source
Revision
237463
Author
[email protected]
Date
2018-10-26 10:07:49 -0700 (Fri, 26 Oct 2018)

Log Message

Use random() instead of begin() to limit cache sizes
https://bugs.webkit.org/show_bug.cgi?id=190957

Reviewed by Chris Dumez.

Source/WebCore:

We currently use cache.remove(cache.begin()) pattern to limit sized of various caches.
This is a bad pattern for tables that never rehash (because they have fixed maximum size) as most of the
keys get permanently stuck in the table.

* css/CSSValuePool.cpp:
(WebCore::CSSValuePool::createColorValue):
(WebCore::CSSValuePool::createFontFamilyValue):
(WebCore::CSSValuePool::createFontFaceValue):
* dom/InlineStyleSheetOwner.cpp:
(WebCore::InlineStyleSheetOwner::createSheet):
* dom/SelectorQuery.cpp:
* platform/graphics/FontCascade.cpp:
(WebCore::retrieveOrAddCachedFonts):
* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::shouldAutoActivateFontIfNeeded):
* platform/mac/PublicSuffixMac.mm:
(WebCore::topPrivatelyControlledDomain):

Source/WebKit:

* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::didCollectPrewarmInformation):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (237462 => 237463)


--- trunk/Source/WebCore/ChangeLog	2018-10-26 16:47:37 UTC (rev 237462)
+++ trunk/Source/WebCore/ChangeLog	2018-10-26 17:07:49 UTC (rev 237463)
@@ -1,3 +1,28 @@
+2018-10-26  Antti Koivisto  <[email protected]>
+
+        Use random() instead of begin() to limit cache sizes
+        https://bugs.webkit.org/show_bug.cgi?id=190957
+
+        Reviewed by Chris Dumez.
+
+        We currently use cache.remove(cache.begin()) pattern to limit sized of various caches.
+        This is a bad pattern for tables that never rehash (because they have fixed maximum size) as most of the
+        keys get permanently stuck in the table.
+
+        * css/CSSValuePool.cpp:
+        (WebCore::CSSValuePool::createColorValue):
+        (WebCore::CSSValuePool::createFontFamilyValue):
+        (WebCore::CSSValuePool::createFontFaceValue):
+        * dom/InlineStyleSheetOwner.cpp:
+        (WebCore::InlineStyleSheetOwner::createSheet):
+        * dom/SelectorQuery.cpp:
+        * platform/graphics/FontCascade.cpp:
+        (WebCore::retrieveOrAddCachedFonts):
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::shouldAutoActivateFontIfNeeded):
+        * platform/mac/PublicSuffixMac.mm:
+        (WebCore::topPrivatelyControlledDomain):
+
 2018-10-26  Jer Noble  <[email protected]>
 
         Adopt -setOverrideRouteSharingPolicy:routingContextUID: SPI

Modified: trunk/Source/WebCore/css/CSSValuePool.cpp (237462 => 237463)


--- trunk/Source/WebCore/css/CSSValuePool.cpp	2018-10-26 16:47:37 UTC (rev 237462)
+++ trunk/Source/WebCore/css/CSSValuePool.cpp	2018-10-26 17:07:49 UTC (rev 237463)
@@ -87,7 +87,7 @@
     // FIXME: Use TinyLRUCache instead?
     const int maximumColorCacheSize = 512;
     if (m_colorValueCache.size() >= maximumColorCacheSize)
-        m_colorValueCache.remove(m_colorValueCache.begin());
+        m_colorValueCache.remove(m_colorValueCache.random());
 
     return *m_colorValueCache.ensure(color, [&color] {
         return CSSPrimitiveValue::create(color);
@@ -123,7 +123,7 @@
     // FIXME: Use TinyLRUCache instead?
     const int maximumFontFamilyCacheSize = 128;
     if (m_fontFamilyValueCache.size() >= maximumFontFamilyCacheSize)
-        m_fontFamilyValueCache.remove(m_fontFamilyValueCache.begin());
+        m_fontFamilyValueCache.remove(m_fontFamilyValueCache.random());
 
     bool isFromSystemID = fromSystemFontID == FromSystemFontID::Yes;
     return *m_fontFamilyValueCache.ensure({ familyName, isFromSystemID }, [&familyName, isFromSystemID] {
@@ -137,7 +137,7 @@
     // FIXME: Use TinyLRUCache instead?
     const int maximumFontFaceCacheSize = 128;
     if (m_fontFaceValueCache.size() >= maximumFontFaceCacheSize)
-        m_fontFaceValueCache.remove(m_fontFaceValueCache.begin());
+        m_fontFaceValueCache.remove(m_fontFaceValueCache.random());
 
     return m_fontFaceValueCache.ensure(string, [&string] () -> RefPtr<CSSValueList> {
         auto result = CSSParser::parseSingleValue(CSSPropertyFontFamily, string);

Modified: trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp (237462 => 237463)


--- trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp	2018-10-26 16:47:37 UTC (rev 237462)
+++ trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp	2018-10-26 17:07:49 UTC (rev 237463)
@@ -218,8 +218,9 @@
         // Prevent pathological growth.
         const size_t maximumInlineStyleSheetCacheSize = 50;
         if (inlineStyleSheetCache().size() > maximumInlineStyleSheetCacheSize) {
-            inlineStyleSheetCache().begin()->value->removedFromMemoryCache();
-            inlineStyleSheetCache().remove(inlineStyleSheetCache().begin());
+            auto toRemove = inlineStyleSheetCache().random();
+            toRemove->value->removedFromMemoryCache();
+            inlineStyleSheetCache().remove(toRemove);
         }
     }
 }

Modified: trunk/Source/WebCore/dom/SelectorQuery.cpp (237462 => 237463)


--- trunk/Source/WebCore/dom/SelectorQuery.cpp	2018-10-26 16:47:37 UTC (rev 237462)
+++ trunk/Source/WebCore/dom/SelectorQuery.cpp	2018-10-26 17:07:49 UTC (rev 237463)
@@ -631,7 +631,7 @@
 
     const int maximumSelectorQueryCacheSize = 256;
     if (m_entries.size() == maximumSelectorQueryCacheSize)
-        m_entries.remove(m_entries.begin());
+        m_entries.remove(m_entries.random());
 
     return *m_entries.add(selectors, std::make_unique<SelectorQuery>(WTFMove(selectorList))).iterator->value;
 }

Modified: trunk/Source/WebCore/platform/graphics/FontCascade.cpp (237462 => 237463)


--- trunk/Source/WebCore/platform/graphics/FontCascade.cpp	2018-10-26 16:47:37 UTC (rev 237462)
+++ trunk/Source/WebCore/platform/graphics/FontCascade.cpp	2018-10-26 17:07:49 UTC (rev 237463)
@@ -265,7 +265,7 @@
         pruneUnreferencedEntriesFromFontCascadeCache();
     // Prevent pathological growth.
     if (fontCascadeCache().size() > maximumEntries)
-        fontCascadeCache().remove(fontCascadeCache().begin());
+        fontCascadeCache().remove(fontCascadeCache().random());
     return glyphs;
 }
 

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp (237462 => 237463)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2018-10-26 16:47:37 UTC (rev 237462)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp	2018-10-26 17:07:49 UTC (rev 237463)
@@ -1238,7 +1238,7 @@
     static const unsigned maxCacheSize = 128;
     ASSERT(knownFamilies.get().size() <= maxCacheSize);
     if (knownFamilies.get().size() == maxCacheSize)
-        knownFamilies.get().remove(knownFamilies.get().begin());
+        knownFamilies.get().remove(knownFamilies.get().random());
 
     // Only attempt to auto-activate fonts once for performance reasons.
     return knownFamilies.get().add(family).isNewEntry;

Modified: trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm (237462 => 237463)


--- trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm	2018-10-26 16:47:37 UTC (rev 237462)
+++ trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm	2018-10-26 17:07:49 UTC (rev 237463)
@@ -59,7 +59,7 @@
 
     constexpr auto maximumSizeToPreventUnlimitedGrowth = 128;
     if (cache.get().size() == maximumSizeToPreventUnlimitedGrowth)
-        cache.get().clear();
+        cache.get().remove(cache.get().random());
 
     return cache.get().ensure(isolatedDomain, [&isolatedDomain] {
         const auto lowercaseDomain = isolatedDomain.convertToASCIILowercase();

Modified: trunk/Source/WebKit/ChangeLog (237462 => 237463)


--- trunk/Source/WebKit/ChangeLog	2018-10-26 16:47:37 UTC (rev 237462)
+++ trunk/Source/WebKit/ChangeLog	2018-10-26 17:07:49 UTC (rev 237463)
@@ -1,3 +1,13 @@
+2018-10-26  Antti Koivisto  <[email protected]>
+
+        Use random() instead of begin() to limit cache sizes
+        https://bugs.webkit.org/show_bug.cgi?id=190957
+
+        Reviewed by Chris Dumez.
+
+        * UIProcess/WebProcessPool.cpp:
+        (WebKit::WebProcessPool::didCollectPrewarmInformation):
+
 2018-10-26  Chris Dumez  <[email protected]>
 
         Modernize / Simplify IPC::Connection::sendOutgoingMessage()

Modified: trunk/Source/WebKit/UIProcess/WebProcessPool.cpp (237462 => 237463)


--- trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-10-26 16:47:37 UTC (rev 237462)
+++ trunk/Source/WebKit/UIProcess/WebProcessPool.cpp	2018-10-26 17:07:49 UTC (rev 237463)
@@ -2282,7 +2282,7 @@
 {
     static const size_t maximumSizeToPreventUnlimitedGrowth = 100;
     if (m_prewarmInformationPerRegistrableDomain.size() == maximumSizeToPreventUnlimitedGrowth)
-        m_prewarmInformationPerRegistrableDomain.remove(m_prewarmInformationPerRegistrableDomain.begin());
+        m_prewarmInformationPerRegistrableDomain.remove(m_prewarmInformationPerRegistrableDomain.random());
 
     auto& value = m_prewarmInformationPerRegistrableDomain.ensure(registrableDomain, [] {
         return std::make_unique<WebCore::PrewarmInformation>();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to