Skip to content

Commit df304d0

Browse files
Jettison on top level navigation
1 parent 926d994 commit df304d0

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

Source/WebCore/loader/FrameLoader.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#include "IgnoreOpensDuringUnloadCountIncrementer.h"
8484
#include "InspectorController.h"
8585
#include "InspectorInstrumentation.h"
86+
#include "LegacySchemeRegistry.h"
8687
#include "LinkLoader.h"
8788
#include "LoaderStrategy.h"
8889
#include "LocalDOMWindow.h"
@@ -2226,7 +2227,8 @@ void FrameLoader::commitProvisionalLoad()
22262227
// We are doing this here because we know for sure that a new page is about to be loaded.
22272228
BackForwardCache::singleton().addIfCacheable(*frame->history().protectedCurrentItem(), frame->protectedPage().get());
22282229

2229-
WebCore::jettisonExpensiveObjectsOnTopLevelNavigation();
2230+
if (pdl && LegacySchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(pdl->request().url().protocol().toStringWithoutCopying()))
2231+
WebCore::jettisonExpensiveObjectsOnTopLevelNavigation();
22302232
}
22312233

22322234
if (m_loadType != FrameLoadType::Replace)

Source/WebCore/page/MemoryRelease.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,24 @@ void logMemoryStatistics(LogMemoryStatisticsReason reason)
253253
void platformReleaseMemory(Critical) { }
254254
#endif
255255
void platformReleaseGraphicsMemory(Critical) { }
256-
void jettisonExpensiveObjectsOnTopLevelNavigation() { }
256+
void jettisonExpensiveObjectsOnTopLevelNavigation()
257+
{
258+
// based on code from cocoa/MemoryReleaseCocoa.mm
259+
// Protect against doing excessive jettisoning during repeated navigations.
260+
const auto minimumTimeSinceNavigation = std::chrono::seconds(2);
261+
262+
const auto now = std::chrono::steady_clock::now();
263+
static auto timeOfLastNavigation = now;
264+
const bool shouldJettison = (timeOfLastNavigation == now) || (std::chrono::duration_cast<std::chrono::seconds>(now - timeOfLastNavigation) >= minimumTimeSinceNavigation);
265+
timeOfLastNavigation = now;
266+
267+
if (!shouldJettison)
268+
return;
269+
270+
RunLoop::main().dispatch([]{
271+
releaseMemory(Critical::Yes, Synchronous::Yes);
272+
});
273+
}
257274
void registerMemoryReleaseNotifyCallbacks() { }
258275
#endif
259276

0 commit comments

Comments
 (0)