Title: [197254] trunk/Source/WebCore
Revision
197254
Author
[email protected]
Date
2016-02-27 09:49:29 -0800 (Sat, 27 Feb 2016)

Log Message

[iOS] Discard decoded image data on top-level navigation.
<https://webkit.org/b/154776>

Reviewed by Anders Carlsson.

Add a mechanism that destroys decoded data for all CachedImages and invoke it
when performing a top-level navigation on iOS.

This substantially reduces the ImageIO contribution to our peak memory footprint.

It would be even better if we could mark these images volatile during the transition
but we currently don't have framework support for such machinations.

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::commitProvisionalLoad):
* loader/cache/MemoryCache.cpp:
(WebCore::MemoryCache::forEachResource):
(WebCore::MemoryCache::destroyDecodedDataForAllImages):
* loader/cache/MemoryCache.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (197253 => 197254)


--- trunk/Source/WebCore/ChangeLog	2016-02-27 15:10:10 UTC (rev 197253)
+++ trunk/Source/WebCore/ChangeLog	2016-02-27 17:49:29 UTC (rev 197254)
@@ -1,3 +1,25 @@
+2016-02-27  Andreas Kling  <[email protected]>
+
+        [iOS] Discard decoded image data on top-level navigation.
+        <https://webkit.org/b/154776>
+
+        Reviewed by Anders Carlsson.
+
+        Add a mechanism that destroys decoded data for all CachedImages and invoke it
+        when performing a top-level navigation on iOS.
+
+        This substantially reduces the ImageIO contribution to our peak memory footprint.
+
+        It would be even better if we could mark these images volatile during the transition
+        but we currently don't have framework support for such machinations.
+
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::commitProvisionalLoad):
+        * loader/cache/MemoryCache.cpp:
+        (WebCore::MemoryCache::forEachResource):
+        (WebCore::MemoryCache::destroyDecodedDataForAllImages):
+        * loader/cache/MemoryCache.h:
+
 2016-02-26  Carlos Garcia Campos  <[email protected]>
 
         Network cache: old pages returned by disk cache on history navigation after session is restored

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (197253 => 197254)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2016-02-27 15:10:10 UTC (rev 197253)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2016-02-27 17:49:29 UTC (rev 197254)
@@ -1766,6 +1766,10 @@
         // For top-level navigations, have JSC throw away linked code. The immediate memory savings far
         // outweigh the cost of recompiling in the case of a future backwards navigation.
         GCController::singleton().deleteAllLinkedCode();
+
+        // Throw out decoded data for CachedImages when we are switching pages. The majority of it
+        // will not be used by the next page.
+        MemoryCache::singleton().destroyDecodedDataForAllImages();
 #endif
     }
 

Modified: trunk/Source/WebCore/loader/cache/MemoryCache.cpp (197253 => 197254)


--- trunk/Source/WebCore/loader/cache/MemoryCache.cpp	2016-02-27 15:10:10 UTC (rev 197253)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.cpp	2016-02-27 17:49:29 UTC (rev 197254)
@@ -277,6 +277,22 @@
     pruneLiveResourcesToSize(targetSize, shouldDestroyDecodedDataForAllLiveResources);
 }
 
+void MemoryCache::forEachResource(const std::function<void(CachedResource&)>& function)
+{
+    for (auto& lruList : m_allResources) {
+        for (auto& resource : *lruList)
+            function(*resource);
+    }
+}
+
+void MemoryCache::destroyDecodedDataForAllImages()
+{
+    MemoryCache::singleton().forEachResource([](CachedResource& resource) {
+        if (resource.isImage())
+            resource.destroyDecodedData();
+    });
+}
+
 void MemoryCache::pruneLiveResourcesToSize(unsigned targetSize, bool shouldDestroyDecodedDataForAllLiveResources)
 {
     if (m_inPruneResources)

Modified: trunk/Source/WebCore/loader/cache/MemoryCache.h (197253 => 197254)


--- trunk/Source/WebCore/loader/cache/MemoryCache.h	2016-02-27 15:10:10 UTC (rev 197253)
+++ trunk/Source/WebCore/loader/cache/MemoryCache.h	2016-02-27 17:49:29 UTC (rev 197254)
@@ -101,6 +101,9 @@
     
     void revalidationSucceeded(CachedResource& revalidatingResource, const ResourceResponse&);
     void revalidationFailed(CachedResource& revalidatingResource);
+
+    void forEachResource(const std::function<void(CachedResource&)>&);
+    void destroyDecodedDataForAllImages();
     
     // Sets the cache's memory capacities, in bytes. These will hold only approximately, 
     // since the decoded cost of resources like scripts and stylesheets is not known.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to