Changeset 202166 in webkit


Ignore:
Timestamp:
Jun 17, 2016 6:35:32 AM (8 years ago)
Author:
akling@apple.com
Message:

[iOS] Throw away linked code when navigating to a new page.
<https://webkit.org/b/153851>

Reviewed by Antti Koivisto.

When navigating to a new page, tell JSC to throw out any linked code it has lying around.
Linked code is tied to a specific global object, and as we're creating a new one for the
new page, none of it is useful to us here.

In the event that the user navigates back, the cost of relinking some code will be far
lower than the memory cost of keeping all of it around.

This was in-tree before but was rolled out due to regressing JSBench. It was a slowdown
due to the benchmark harness using top-level navigations to drive the tests.
This new version avoids that problem by only throwing out code if we haven't navigated
in the last 2 seconds. This also prevents excessive work in response to redirects.

I've also moved this into MemoryPressureHandler so we don't make a mess in FrameLoader.

  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::commitProvisionalLoad):

  • platform/MemoryPressureHandler.cpp:

(WebCore::MemoryPressureHandler::jettisonExpensiveObjectsOnTopLevelNavigation):

  • platform/MemoryPressureHandler.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r202162 r202166  
     12016-06-17  Andreas Kling  <akling@apple.com>
     2
     3        [iOS] Throw away linked code when navigating to a new page.
     4        <https://webkit.org/b/153851>
     5
     6        Reviewed by Antti Koivisto.
     7
     8        When navigating to a new page, tell JSC to throw out any linked code it has lying around.
     9        Linked code is tied to a specific global object, and as we're creating a new one for the
     10        new page, none of it is useful to us here.
     11
     12        In the event that the user navigates back, the cost of relinking some code will be far
     13        lower than the memory cost of keeping all of it around.
     14
     15        This was in-tree before but was rolled out due to regressing JSBench. It was a slowdown
     16        due to the benchmark harness using top-level navigations to drive the tests.
     17        This new version avoids that problem by only throwing out code if we haven't navigated
     18        in the last 2 seconds. This also prevents excessive work in response to redirects.
     19
     20        I've also moved this into MemoryPressureHandler so we don't make a mess in FrameLoader.
     21
     22        * loader/FrameLoader.cpp:
     23        (WebCore::FrameLoader::commitProvisionalLoad):
     24        * platform/MemoryPressureHandler.cpp:
     25        (WebCore::MemoryPressureHandler::jettisonExpensiveObjectsOnTopLevelNavigation):
     26        * platform/MemoryPressureHandler.h:
     27
    1282016-06-17  Youenn Fablet  <youenn.fablet@crf.canon.fr>
    229
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r202139 r202166  
    17871787        // We are doing this here because we know for sure that a new page is about to be loaded.
    17881788        PageCache::singleton().addIfCacheable(*history().currentItem(), m_frame.page());
     1789       
     1790        MemoryPressureHandler::singleton().jettisonExpensiveObjectsOnTopLevelNavigation();
    17891791    }
    17901792
  • trunk/Source/WebCore/platform/MemoryPressureHandler.cpp

    r202090 r202166  
    4242#include "WorkerThread.h"
    4343#include <JavaScriptCore/IncrementalSweeper.h>
     44#include <chrono>
    4445#include <wtf/CurrentTime.h>
    4546#include <wtf/FastMalloc.h>
     
    160161}
    161162
     163void MemoryPressureHandler::jettisonExpensiveObjectsOnTopLevelNavigation()
     164{
     165#if PLATFORM(IOS)
     166    // Protect against doing excessive jettisoning during repeated navigations.
     167    const auto minimumTimeSinceNavigation = 2s;
     168
     169    static auto timeOfLastNavigation = std::chrono::steady_clock::now();
     170    auto now = std::chrono::steady_clock::now();
     171    bool shouldJettison = now - timeOfLastNavigation >= minimumTimeSinceNavigation;
     172    timeOfLastNavigation = now;
     173
     174    if (!shouldJettison)
     175        return;
     176
     177    // Throw away linked JS code. Linked code is tied to a global object and is not reusable.
     178    // The immediate memory savings outweigh the cost of recompilation in case we go back again.
     179    GCController::singleton().deleteAllLinkedCode();
     180#endif
     181}
     182
    162183void MemoryPressureHandler::releaseMemory(Critical critical, Synchronous synchronous)
    163184{
  • trunk/Source/WebCore/platform/MemoryPressureHandler.h

    r202090 r202166  
    6969        m_lowMemoryHandler = handler;
    7070    }
     71
     72    void jettisonExpensiveObjectsOnTopLevelNavigation();
    7173
    7274    bool isUnderMemoryPressure() const { return m_underMemoryPressure; }
Note: See TracChangeset for help on using the changeset viewer.