Changeset 210224 in webkit


Ignore:
Timestamp:
Jan 2, 2017 7:36:41 AM (7 years ago)
Author:
akling@apple.com
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.

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r210116 r210224  
     12017-01-02  Andreas Kling  <akling@apple.com>
     2
     3        Discard media controls JS/CSS caches under memory pressure.
     4        <https://webkit.org/b/166639>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * wtf/text/WTFString.h:
     9        (WTF::String::clearImplIfNotShared): Add a helper for clearing a String if the underlying
     10        StringImpl is not referenced by anyone else.
     11
    1122016-12-22  Mark Lam  <mark.lam@apple.com>
    213
  • trunk/Source/WTF/wtf/text/WTFString.h

    r206804 r210224  
    468468            return 0;
    469469        return (*m_impl)[index];
     470    }
     471
     472    // Turns this String empty if the StringImpl is not referenced by anyone else.
     473    // This is useful for clearing String-based caches.
     474    void clearImplIfNotShared()
     475    {
     476        if (m_impl && m_impl->hasOneRef())
     477            m_impl = nullptr;
    470478    }
    471479
  • trunk/Source/WebCore/ChangeLog

    r210223 r210224  
     12017-01-02  Andreas Kling  <akling@apple.com>
     2
     3        Discard media controls JS/CSS caches under memory pressure.
     4        <https://webkit.org/b/166639>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Add a RenderTheme::purgeCaches() virtual and teach the iOS and macOS implementations
     9        to drop their cached media controls JS/CSS strings there. The strings are only cleared
     10        if nothing else is referencing them, which gives us a decent "weak cache" behavior.
     11
     12        This sheds ~300kB memory on iOS with the current media controls.
     13
     14        * page/MemoryRelease.cpp:
     15        (WebCore::releaseNoncriticalMemory):
     16        * rendering/RenderTheme.h:
     17        (WebCore::RenderTheme::purgeCaches):
     18        * rendering/RenderThemeIOS.h:
     19        * rendering/RenderThemeIOS.mm:
     20        (WebCore::RenderThemeIOS::purgeCaches):
     21        * rendering/RenderThemeMac.h:
     22        * rendering/RenderThemeMac.mm:
     23        (WebCore::RenderThemeMac::purgeCaches):
     24
    1252017-01-02  Carlos Garcia Campos  <cgarcia@igalia.com>
    226
  • trunk/Source/WebCore/page/MemoryRelease.cpp

    r209744 r210224  
    3939#include "Page.h"
    4040#include "PageCache.h"
     41#include "RenderTheme.h"
    4142#include "ScrollingThread.h"
    4243#include "StyleScope.h"
     
    4950static void releaseNoncriticalMemory()
    5051{
     52    RenderTheme::defaultTheme()->purgeCaches();
     53
    5154    FontCache::singleton().purgeInactiveFontData();
    5255
  • trunk/Source/WebCore/rendering/RenderTheme.h

    r208668 r210224  
    7373    };
    7474
     75    virtual void purgeCaches() { }
     76
    7577    // This method is called whenever style has been computed for an element and the appearance
    7678    // property has been set to a value other than "none".  The theme should map in all of the appropriate
  • trunk/Source/WebCore/rendering/RenderThemeIOS.h

    r209441 r210224  
    122122    virtual ~RenderThemeIOS() { }
    123123
     124    void purgeCaches() override;
     125
    124126    const Color& shadowColor() const;
    125127    FloatRect addRoundedBorderClip(const RenderObject& box, GraphicsContext&, const IntRect&);
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r209441 r210224  
    13061306}
    13071307
     1308void RenderThemeIOS::purgeCaches()
     1309{
     1310    m_legacyMediaControlsScript.clearImplIfNotShared();
     1311    m_mediaControlsScript.clearImplIfNotShared();
     1312    m_legacyMediaControlsStyleSheet.clearImplIfNotShared();
     1313    m_mediaControlsStyleSheet.clearImplIfNotShared();
     1314}
     1315
    13081316String RenderThemeIOS::mediaControlsScript()
    13091317{
  • trunk/Source/WebCore/rendering/RenderThemeMac.h

    r209417 r210224  
    172172
    173173    Color systemColor(CSSValueID) const override;
     174
     175    void purgeCaches() override;
    174176
    175177    // Get the control size based off the font. Used by some of the controls (like buttons).
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r209417 r210224  
    247247}
    248248
     249void RenderThemeMac::purgeCaches()
     250{
     251    m_legacyMediaControlsScript.clearImplIfNotShared();
     252    m_mediaControlsScript.clearImplIfNotShared();
     253    m_legacyMediaControlsStyleSheet.clearImplIfNotShared();
     254    m_mediaControlsStyleSheet.clearImplIfNotShared();
     255}
     256
    249257String RenderThemeMac::mediaControlsScript()
    250258{
Note: See TracChangeset for help on using the changeset viewer.