Skip to content

Commit f0efd54

Browse files
pgorszkowski-igaliamagomez
authored andcommitted
Jettison on top level navigation
1 parent 5314c7b commit f0efd54

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
@@ -84,6 +84,7 @@
8484
#include "IgnoreOpensDuringUnloadCountIncrementer.h"
8585
#include "InspectorController.h"
8686
#include "InspectorInstrumentation.h"
87+
#include "LegacySchemeRegistry.h"
8788
#include "LinkLoader.h"
8889
#include "LoaderStrategy.h"
8990
#include "LocalDOMWindow.h"
@@ -2237,7 +2238,8 @@ void FrameLoader::commitProvisionalLoad()
22372238
// We are doing this here because we know for sure that a new page is about to be loaded.
22382239
BackForwardCache::singleton().addIfCacheable(*frame->history().protectedCurrentItem(), frame->protectedPage().get());
22392240

2240-
WebCore::jettisonExpensiveObjectsOnTopLevelNavigation();
2241+
if (pdl && LegacySchemeRegistry::shouldLoadURLSchemeAsEmptyDocument(pdl->request().url().protocol().toStringWithoutCopying()))
2242+
WebCore::jettisonExpensiveObjectsOnTopLevelNavigation();
22412243
}
22422244

22432245
if (m_loadType != FrameLoadType::Replace)

Source/WebCore/page/MemoryRelease.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,24 @@ void logMemoryStatistics(LogMemoryStatisticsReason reason)
262262
void platformReleaseMemory(Critical) { }
263263
#endif
264264
void platformReleaseGraphicsMemory(Critical) { }
265-
void jettisonExpensiveObjectsOnTopLevelNavigation() { }
265+
void jettisonExpensiveObjectsOnTopLevelNavigation()
266+
{
267+
// based on code from cocoa/MemoryReleaseCocoa.mm
268+
// Protect against doing excessive jettisoning during repeated navigations.
269+
const auto minimumTimeSinceNavigation = std::chrono::seconds(2);
270+
271+
const auto now = std::chrono::steady_clock::now();
272+
static auto timeOfLastNavigation = now;
273+
const bool shouldJettison = (timeOfLastNavigation == now) || (std::chrono::duration_cast<std::chrono::seconds>(now - timeOfLastNavigation) >= minimumTimeSinceNavigation);
274+
timeOfLastNavigation = now;
275+
276+
if (!shouldJettison)
277+
return;
278+
279+
RunLoop::main().dispatch([]{
280+
releaseMemory(Critical::Yes, Synchronous::Yes);
281+
});
282+
}
266283
void registerMemoryReleaseNotifyCallbacks() { }
267284
#endif
268285

0 commit comments

Comments
 (0)