Repository navigation
Renderer test helpers: a fresh stage page in WebKit every 8 frames (#151) - #160
Merged
Merged
Conversation
) WebKit keeps every iframe a page has removed, with its document and script heap, until the page itself navigates. Each stage load that doesn't reuse its frame starts a new one, so a spec that loads scenario after scenario in one page (diff mode over every graph scenario, the arrowheads loop) grows the web process, which also runs the sandboxed renderer frames, by 5-20 MB per load until it thrashes collecting garbage or the system kills it: a stage that reports ready, then a page whose event loop never runs again, then "Target page... closed". openStage and checkScenario now count the frames a page attaches since its main frame navigated, and in WebKit reload the stage page once that reaches 8, which releases them. Fixes #151 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The refresh budget is checked only before the entire check suite, allowing a single suite to exceed eight frames and leave long WebKit runs exposed to retained-frame memory growth.
1 open issue
What changed in this PR
Addresses the WebKit memory growth investigated in #151 by refreshing renderer stage pages after repeated frame creation, complementing #153’s request timeout diagnostics.
Changes:
- Track frame attachments and reload WebKit stage pages when the eight-frame budget is reached between helper calls.
- Add regression coverage for frame counting, navigation resets, and Chromium behavior.
- Document reload-related state loss and clarify the timeout comment.
| File | Description |
|---|---|
packages/renderers/testing/test/helpers.test.mjs |
Tests frame counting, reset behavior, and engine-specific refresh decisions. |
packages/renderers/testing/README.md |
Documents WebKit reloads and loss of in-page state. |
packages/renderers/testing/playwright/index.ts |
Applies the refresh check during stage-page preparation. |
packages/renderers/testing/playwright/frames.ts |
Adds per-page frame tracking and the WebKit refresh threshold. |
packages/renderers/testing/playwright/bounded.ts |
Updates a comment to explain memory-related page hangs. |
Review effort: Balanced
…age page checkScenario ran the whole check suite in one request, starting its frames inside the page where stagePage can't start it over: one suite for a large graph (npm-express-5) attached 44 frames and grew WebKit's web process by about 1.5 GB. In WebKit it now runs the checks three at a time (two to five frames each), reloading the stage page before each batch that follows any frame. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What changed
Fixes #151. This is not a layout or routing loop: WebKit runs out of memory.
WebKit keeps every iframe a page has removed, with its document and script heap, until the page itself navigates. Each stage load that doesn't
reuseits frame starts a new one. A spec that loads scenario after scenario in one page (diff.spec.ts:36, the arrowheads loop) therefore grows the WebProcess by about 5–20 MB per load. In WebKit that process also runs the sandboxed renderer frames. It grows until it thrashes in garbage collection or the system kills it. The result is a stage that reports ready, then a page whose event loop never runs again, then "Target page… closed".openStageandcheckScenario(in@githubnext/projections-renderer-testing) now count the frames a page attaches since its main frame last navigated. In WebKit they reload the stage page once that count reaches 8 (framesPerStagePage), which releases those frames. Chromium frees removed frames itself, so it's unchanged.checkScenarioruns its whole suite inside the page, out of reach of that reload: one suite forgraph/npm-express-5attached 44 frames and grew the WebProcess by about 1.5 GB. So in WebKit it now runs the checks three at a time (each attaches 2–5 frames) and reloads before every batch that follows any frame. Init scripts survive the reload; in-page state from before the reload does not, and the README now says so.How I found it (Linux, Playwright WebKit):
dmesgshowed the OOM killer killingWPEWebProcessat 2.9 GB. On the stall, the surviving WebProcess main thread sat idle inpoll()at 0% CPU, so no JS or layout loop was spinning.kit/src/layout/**,routing/*, fit and zoom) are all bounded. I found no pathological input.reuse: true(same frame).initand no renderer code running, isolates the cause. A renderer document parsed but never executed still grows RSS by 2.7 MB per frame. A 2 MB script-free text document grows it by 5 MB per frame. A tiny document barely grows it. Forcing GC pressure doesn't reclaim the memory; reloading the page does (577 → 482 MB).Evidence
WebKit
release-workflow× 40 loads in one page: before, about 20 MB/load, linear (956 MB at load 24). After, it plateaus around 670–800 MB.The 28-scenario graph loop, 2 workers × 4 rounds (448 loads), WebKit,
CI=1: before, both workers stalled or were OOM-killed in round 2. After, it passes in 8 min.browser/diff.spec.ts+browser/arrowheads.spec.ts,--project=webkit-desktop,CI=1: 25 passed (and again after rebasing on Renderer test helpers: bound each stage request, and say what the stage last showed #153).browser/checks.spec.ts, WebKit,CI=1: 26 passed. Memory after each check suite no longer accumulates (1085 → 993 → 954 MB across three scenarios).Unit test (
test/helpers.test.mjs): the frame count resets only on a main-frame navigation; WebKit at the limit gets a fresh page; Chromium never does.npm run tools -- check --fastandcheck --affectedpass.Documentation that this change affects is updated, and generated reference
pages are regenerated (
npm run docs:generate).Fixes include a regression test.
No credentials, private source or machine-specific paths are included.