Repository navigation
perf(audit-engine): detach the streamed page universe from the pages it parsed - #237
Merged
Merged
Conversation
…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]>
This was referenced Sep 7, 2026
Merged
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.
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:
At 500 pages the first row is 1.9 GB of retention against 38 MB. The second row is small because
JSON.parsealready returns fresh strings: a stored parse was never the thing holding the page.Two things the clone cannot do naively:
documentis 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.schemasis aSchemaCollection, a class with getters.structuredClonekeeps its data and loses its prototype, so it is rebuilt withschemaCollectionFromJSON— the same rehydrationbuildSiteContextalready does for a parse that came out of storage.Both consumers share the one copy, because
runSitePass's soft-404 confirm mutates the parse throughpageDataMapandparsedPageshas 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.tsadds 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.tsis 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.