Skip to content

[WebKitSettings] Add API for OpportunisticSweepingAndGarbageCollectio…#1612

Merged
magomez merged 1 commit intoWebPlatformForEmbedded:wpe-2.46from
asurdej-comcast:opportunistic_gc
Feb 5, 2026
Merged

[WebKitSettings] Add API for OpportunisticSweepingAndGarbageCollectio…#1612
magomez merged 1 commit intoWebPlatformForEmbedded:wpe-2.46from
asurdej-comcast:opportunistic_gc

Conversation

@asurdej-comcast
Copy link
Copy Markdown

@asurdej-comcast asurdej-comcast commented Feb 5, 2026

…nEnabled

We observe increased WebKit 2.46 average memory usage (vs 2.38) with OpportunisticSweepingAndGarbageCollectionEnabled. In case of LightningApps (webgl/non composited webgl) this option effectively disables GC timers in some cases (FullGCActivityCallback and EdenGCActivityCallback) and prevents them from running.
Initially reported as memory during video playback but I can observe it also with UI scrolling

The only source of GC is Heap.cpp:

2026-02-05 06:50:18 Requesting GC because bytes allocated this cycle: 855941 exceed bytes allowed: 817924 (critical) normal bytes: 715034 oversized bytes: 140907 last oversized: 66063
2026-02-05 06:50:18 [GC<0x8c014088>: START M 1020kb => FullCollection, v=0kb (C:0 M:0 P1:0 P2:0 P3:0) o=0 b=87 i#1:N<CsMsrShDMsm(0)> 21+0 v=140kb (C:28 M:0 P1:17 P2:27 P3:66) o=2 b=87 i#2:N<WsOJwJIT Worklists:
2026-02-05 06:50:18 Collector: [], Mutator: []> 0+0 v=140kb (C:28 M:0 P1:17 P2:27 P3:66) o=2 b=87 i#3:P<WsOJwJIT Worklists:
2026-02-05 06:50:18 Collector: [], Mutator: []MsrShCsMsm(0)DCbDomo> => 234kb, p=5.890000ms (max 173.480000), cycle 5.852000ms END]
2026-02-05 06:50:18 GC END!
2026-02-05 06:50:18 [GC<0x8c014088>: finalize 0.225000ms]

GC timers are blocked by OpportunisticTaskScheduler, where isBusyForTimerBasedGC() is always true because of requestAnimationFrame() callback that is set over and over for LightningApp and it considered as imminently scheduled task.

ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCallback(Ref<RequestAnimationFrameCallback>&& callback)
{

    RefPtr<ImminentlyScheduledWorkScope> workScope;
    if (RefPtr page = this->page()) {
        workScope = page->opportunisticTaskScheduler().makeScheduledWorkScope();

Here is how WebProcess memory usage looks for hbomax app steady video playback with webkit 2.38:
marked moments are FullGCActivityCallback, beside that EdenGCActivityCallback triggers GC every 10sec
Screenshot From 2026-02-02 17-49-00
And here is how it looks with 2.46 where GC is invoked at spikes only, every ~1min. Full gc is marked with a red circle while other points are Eden GC
Screenshot From 2026-02-02 18-17-17

Disabling OpportunisticSweepingAndGarbageCollectionEnabled brings back wpe-2.38 behavior.

WebKit/WebKit@5c9eac4
WebKit/WebKit#20688

@magomez
Copy link
Copy Markdown

magomez commented Feb 5, 2026

Amazing findings @asurdej-comcast !! Thanks for the debug!!

@magomez magomez merged commit 0e58074 into WebPlatformForEmbedded:wpe-2.46 Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants