Title: [210224] trunk/Source
Revision
210224
Author
akl...@apple.com
Date
2017-01-02 07:36:41 -0800 (Mon, 02 Jan 2017)

Log Message

Discard media controls JS/CSS caches under memory pressure.
<https://webkit.org/b/166639>

Reviewed by Antti Koivisto.

Source/WebCore:

Add a RenderTheme::purgeCaches() virtual and teach the iOS and macOS implementations
to drop their cached media controls JS/CSS strings there. The strings are only cleared
if nothing else is referencing them, which gives us a decent "weak cache" behavior.

This sheds ~300kB memory on iOS with the current media controls.

* page/MemoryRelease.cpp:
(WebCore::releaseNoncriticalMemory):
* rendering/RenderTheme.h:
(WebCore::RenderTheme::purgeCaches):
* rendering/RenderThemeIOS.h:
* rendering/RenderThemeIOS.mm:
(WebCore::RenderThemeIOS::purgeCaches):
* rendering/RenderThemeMac.h:
* rendering/RenderThemeMac.mm:
(WebCore::RenderThemeMac::purgeCaches):

Source/WTF:

* wtf/text/WTFString.h:
(WTF::String::clearImplIfNotShared): Add a helper for clearing a String if the underlying
StringImpl is not referenced by anyone else.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (210223 => 210224)


--- trunk/Source/WTF/ChangeLog	2017-01-02 13:54:17 UTC (rev 210223)
+++ trunk/Source/WTF/ChangeLog	2017-01-02 15:36:41 UTC (rev 210224)
@@ -1,3 +1,14 @@
+2017-01-02  Andreas Kling  <akl...@apple.com>
+
+        Discard media controls JS/CSS caches under memory pressure.
+        <https://webkit.org/b/166639>
+
+        Reviewed by Antti Koivisto.
+
+        * wtf/text/WTFString.h:
+        (WTF::String::clearImplIfNotShared): Add a helper for clearing a String if the underlying
+        StringImpl is not referenced by anyone else.
+
 2016-12-22  Mark Lam  <mark....@apple.com>
 
         De-duplicate finally blocks.

Modified: trunk/Source/WTF/wtf/text/WTFString.h (210223 => 210224)


--- trunk/Source/WTF/wtf/text/WTFString.h	2017-01-02 13:54:17 UTC (rev 210223)
+++ trunk/Source/WTF/wtf/text/WTFString.h	2017-01-02 15:36:41 UTC (rev 210224)
@@ -469,6 +469,14 @@
         return (*m_impl)[index];
     }
 
+    // Turns this String empty if the StringImpl is not referenced by anyone else.
+    // This is useful for clearing String-based caches.
+    void clearImplIfNotShared()
+    {
+        if (m_impl && m_impl->hasOneRef())
+            m_impl = nullptr;
+    }
+
 private:
     template <typename CharacterType>
     void removeInternal(const CharacterType*, unsigned, int);

Modified: trunk/Source/WebCore/ChangeLog (210223 => 210224)


--- trunk/Source/WebCore/ChangeLog	2017-01-02 13:54:17 UTC (rev 210223)
+++ trunk/Source/WebCore/ChangeLog	2017-01-02 15:36:41 UTC (rev 210224)
@@ -1,3 +1,27 @@
+2017-01-02  Andreas Kling  <akl...@apple.com>
+
+        Discard media controls JS/CSS caches under memory pressure.
+        <https://webkit.org/b/166639>
+
+        Reviewed by Antti Koivisto.
+
+        Add a RenderTheme::purgeCaches() virtual and teach the iOS and macOS implementations
+        to drop their cached media controls JS/CSS strings there. The strings are only cleared
+        if nothing else is referencing them, which gives us a decent "weak cache" behavior.
+
+        This sheds ~300kB memory on iOS with the current media controls.
+
+        * page/MemoryRelease.cpp:
+        (WebCore::releaseNoncriticalMemory):
+        * rendering/RenderTheme.h:
+        (WebCore::RenderTheme::purgeCaches):
+        * rendering/RenderThemeIOS.h:
+        * rendering/RenderThemeIOS.mm:
+        (WebCore::RenderThemeIOS::purgeCaches):
+        * rendering/RenderThemeMac.h:
+        * rendering/RenderThemeMac.mm:
+        (WebCore::RenderThemeMac::purgeCaches):
+
 2017-01-02  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] Since the memory pressure relief has been activated, my disk has a high usage and the desktop stalls

Modified: trunk/Source/WebCore/page/MemoryRelease.cpp (210223 => 210224)


--- trunk/Source/WebCore/page/MemoryRelease.cpp	2017-01-02 13:54:17 UTC (rev 210223)
+++ trunk/Source/WebCore/page/MemoryRelease.cpp	2017-01-02 15:36:41 UTC (rev 210224)
@@ -38,6 +38,7 @@
 #include "MemoryCache.h"
 #include "Page.h"
 #include "PageCache.h"
+#include "RenderTheme.h"
 #include "ScrollingThread.h"
 #include "StyleScope.h"
 #include "StyledElement.h"
@@ -48,6 +49,8 @@
 
 static void releaseNoncriticalMemory()
 {
+    RenderTheme::defaultTheme()->purgeCaches();
+
     FontCache::singleton().purgeInactiveFontData();
 
     clearWidthCaches();

Modified: trunk/Source/WebCore/rendering/RenderTheme.h (210223 => 210224)


--- trunk/Source/WebCore/rendering/RenderTheme.h	2017-01-02 13:54:17 UTC (rev 210223)
+++ trunk/Source/WebCore/rendering/RenderTheme.h	2017-01-02 15:36:41 UTC (rev 210224)
@@ -72,6 +72,8 @@
         return themeForPage(nullptr);
     };
 
+    virtual void purgeCaches() { }
+
     // This method is called whenever style has been computed for an element and the appearance
     // property has been set to a value other than "none".  The theme should map in all of the appropriate
     // metrics and defaults given the contents of the style.  This includes sophisticated operations like

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.h (210223 => 210224)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.h	2017-01-02 13:54:17 UTC (rev 210223)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.h	2017-01-02 15:36:41 UTC (rev 210224)
@@ -121,6 +121,8 @@
     RenderThemeIOS();
     virtual ~RenderThemeIOS() { }
 
+    void purgeCaches() override;
+
     const Color& shadowColor() const;
     FloatRect addRoundedBorderClip(const RenderObject& box, GraphicsContext&, const IntRect&);
 

Modified: trunk/Source/WebCore/rendering/RenderThemeIOS.mm (210223 => 210224)


--- trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2017-01-02 13:54:17 UTC (rev 210223)
+++ trunk/Source/WebCore/rendering/RenderThemeIOS.mm	2017-01-02 15:36:41 UTC (rev 210224)
@@ -1305,6 +1305,14 @@
 #endif
 }
 
+void RenderThemeIOS::purgeCaches()
+{
+    m_legacyMediaControlsScript.clearImplIfNotShared();
+    m_mediaControlsScript.clearImplIfNotShared();
+    m_legacyMediaControlsStyleSheet.clearImplIfNotShared();
+    m_mediaControlsStyleSheet.clearImplIfNotShared();
+}
+
 String RenderThemeIOS::mediaControlsScript()
 {
 #if ENABLE(MEDIA_CONTROLS_SCRIPT)

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.h (210223 => 210224)


--- trunk/Source/WebCore/rendering/RenderThemeMac.h	2017-01-02 13:54:17 UTC (rev 210223)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.h	2017-01-02 15:36:41 UTC (rev 210224)
@@ -172,6 +172,8 @@
 
     Color systemColor(CSSValueID) const override;
 
+    void purgeCaches() override;
+
     // Get the control size based off the font. Used by some of the controls (like buttons).
     NSControlSize controlSizeForFont(const RenderStyle&) const;
     NSControlSize controlSizeForSystemFont(const RenderStyle&) const;

Modified: trunk/Source/WebCore/rendering/RenderThemeMac.mm (210223 => 210224)


--- trunk/Source/WebCore/rendering/RenderThemeMac.mm	2017-01-02 13:54:17 UTC (rev 210223)
+++ trunk/Source/WebCore/rendering/RenderThemeMac.mm	2017-01-02 15:36:41 UTC (rev 210224)
@@ -246,6 +246,14 @@
 #endif
 }
 
+void RenderThemeMac::purgeCaches()
+{
+    m_legacyMediaControlsScript.clearImplIfNotShared();
+    m_mediaControlsScript.clearImplIfNotShared();
+    m_legacyMediaControlsStyleSheet.clearImplIfNotShared();
+    m_mediaControlsStyleSheet.clearImplIfNotShared();
+}
+
 String RenderThemeMac::mediaControlsScript()
 {
 #if ENABLE(MEDIA_CONTROLS_SCRIPT)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to