Skip to content

perf(audit-engine): detach the streamed page universe from the pages it parsed - #237

Merged
nc9 merged 2 commits into
mainfrom
perf/detach-parsed-universe-1860
Sep 7, 2026
Merged

nc9 merged 2 commits into
mainfrom
perf/detach-parsed-universe-1860

Conversation

@nc9

@nc9 nc9 commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Part of #1860 / the OOM incident.

The streamed universe keeps one parsed page per crawled page for the whole run. When the parse ran against a live DOM, every scalar it holds is a slice of that page's HTML, and JSC keeps a slice attached to the buffer it came from, so one retained href holds a whole 959 KB page as UTF-16 until the audit ends.

Measured over 150 real 959 KB pages, held above a retain-nothing control:

stored parsedData before after
absent (CLI path, and the fallback for older crawls) 3900 KB/page 77 KB/page
present 126 KB/page 100 KB/page

At 500 pages the first row is 1.9 GB of retention against 38 MB. The second row is small because JSON.parse already returns fresh strings: a stored parse was never the thing holding the page.

Two things the clone cannot do naively:

  • document is a live linkedom DOM at that point. Cloning it throws, and the throw is caught, so the whole page would silently stay attached with identical findings and green goldens. It is dropped instead; the universe is DOM-free by contract and the batch's documents are released on the next line.
  • schemas is a SchemaCollection, a class with getters. structuredClone keeps its data and loses its prototype, so it is rebuilt with schemaCollectionFromJSON — the same rehydration buildSiteContext already does for a parse that came out of storage.

Both consumers share the one copy, because runSitePass's soft-404 confirm mutates the parse through pageDataMap and parsedPages has to see that mutation.

Byte identity is the gate: the v1-vs-v2 canonical, streaming, pre-rules, collector and report-stream goldens plus the five site-query goldens all pass. tests/detach-production-boundaries.test.ts adds a real-parse case asserting the DOM is dropped, the schemas still answer through their getters, every other field is equal, and no page took the fallback.

scripts/universe-retention.ts is the measurement. It has a mode that retains nothing, because the JSC arena plateaus flat at ~210 MB on this fixture whatever the page count, and dividing that constant by page count invents a per-page term that is not there.

nc9 added 2 commits September 7, 2026 21:11
…it parsed

The streamed universe keeps one parsed page per crawled page for the whole
run. When the parse ran against a live DOM, every scalar it holds — hrefs,
meta text, heading text — is a slice of that page's HTML, and JSC keeps a
slice attached to the buffer it came from. One retained href holds a whole
959 KB page as UTF-16 until the audit ends.

Measured over 150 real 959 KB pages, held above a retain-nothing control:

  no stored parsedData    3900 KB/page  ->  77 KB/page
  with stored parsedData   126 KB/page  -> 100 KB/page

The first row is the CLI path and the fallback for crawls whose parsedData
is missing; at 500 pages it is 1.9 GB of retention against 38 MB. The second
is small because `JSON.parse` already hands back fresh strings, so a stored
parse was never the one holding the page.

`document` is dropped rather than cloned (a live linkedom DOM throws, and
the throw would silently keep the page attached), and `schemas` is rebuilt
with `schemaCollectionFromJSON` after the clone, because `structuredClone`
keeps a SchemaCollection's data and loses its prototype. Both consumers
share the one copy so `runSitePass`'s soft-404 confirm still mutates the
parse both of them read.

Byte identity is the gate: v1-vs-v2 canonical, streaming, pre-rules,
collector, report-stream and the five site-query goldens all pass.

scripts/universe-retention.ts is the measurement, with a mode that retains
nothing so a per-page figure is taken against a control rather than against
the arena, which is flat at ~210 MB whatever the page count.

Signed-off-by: Nik Cubrilovic <[email protected]>
… the path it is for

Review findings on the parsed-universe detach (#1860).

The new test called `detachParsedPage` directly, so deleting the
accumulator's call site left it green. The streaming run now asserts the
`parsed-universe` counter alongside the other two; removing the call site
fails it (verified).

Its assertions also passed for a shallow copy that merely dropped
`document` while every nested string still pinned the page — the exact
non-fix this change exists to rule out. It now asserts the nested objects
are copies, not the same references.

And it only covered pages WITH a stored parse, which is the path that was
never the problem. It now also runs the no-parsedData path, where the parse
came from a live DOM and the retention is 3900 KB/page.

The helper's doc quoted an early single run; it now quotes the measurement
the commit reports, and says the figures are taken above a retain-nothing
control.

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 merged commit 1806a1b into main Sep 7, 2026
13 checks passed
@nc9
nc9 deleted the perf/detach-parsed-universe-1860 branch September 7, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant