Skip to content

bench: run each section in its own process (#231) - #310

Merged
jonathanKingston merged 2 commits into
mainfrom
claude/project-thread-36pila
Nov 27, 2026
Merged

jonathanKingston merged 2 commits into
mainfrom
claude/project-thread-36pila

Conversation

@jonathanKingston

Copy link
Copy Markdown
Collaborator

Addresses durable fixes 1, 2 and 4 from #231. Item 3 (filing upstream against jsdom) is left for a person to do.

Problem

jsdom permanently retains memory on every string-path DOMPurify sanitize call. The bench ran every section in one process, so the retention from the string-path fixtures table carried into every later section and the job sat close to its heap cap.

Change

scripts/bench-streaming.mts is now a runner. It spawns one child process per section (fixtures, scaling, footnote-scaling, incremental-scan, code-block, real-document, work-shape), one after another so timings don't contend. Each child gets a fresh jsdom and sends its memory back over IPC.

  • Each section prints memory [name]: rss / heapUsed / peak rss.
  • The run ends with a summary of each section's result, wall time and peak RSS. A failing section is named (bench failed in section(s): …), the other sections still run, and the job exits 1.
  • --section <name> runs one section in-process. --in-process keeps the old single-process behaviour.
  • The section bodies are unchanged apart from being wrapped in functions. git diff -w shows the real diff (+247/−24).
  • Docs: the bench section in ARCHITECTURE.md, a jsdom SSR note in SECURITY.md (prefer the sanitizeInto DOM path or recycle workers), and an updated ci.yml comment. The 12288 MB cap stays and now applies to each section.

Measured locally (node 22, jsdom 31)

section peak RSS (isolated)
fixtures 3585 MB
scaling 311 MB
footnote-scaling 354 MB
incremental-scan 164 MB
code-block 345 MB
real-document 291 MB
work-shape 176 MB

With --in-process, the heap climbs from 3.5 GB after fixtures to 4.4 GB by the end, and every section runs on top of what fixtures left behind. real-document, the section that OOM'd in #229, now peaks at about 290 MB. Total wall time went from about 63 s to 69 s, mostly spent starting the child processes.

To check the failure path, I ran with NODE_OPTIONS=--max-old-space-size=300. Only fixtures died (SIGABRT), the other six sections passed, the summary named fixtures, and the exit code was 1.

Follow-up (not in this PR)

fixtures is now the only section that needs gigabytes. Running each of its four fixtures in its own child would cut that further if it matters.


Generated by Claude Code

jsdom permanently retains memory on every string-path DOMPurify sanitize
call, so in one process the bench's string-path fixtures table (~3.5 GB
retained) carried into every later section and kept the job at a heap
cliff. The bench is now a runner that spawns one child per section,
sequentially, and collects each child's memory over IPC.

- Each section prints a `memory [...]` line (rss / heapUsed / peak RSS).
- The runner ends with a per-section summary (result, wall time, peak RSS)
  and names any section that failed; other sections still run.
- `--section <name>` runs one section in-process; `--in-process` keeps
  the old single-process behaviour for comparison.
- Docs: ARCHITECTURE bench section, a jsdom SSR note in SECURITY, and an
  updated ci.yml comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6vooHKVSXCabQW89yiiDs

@jonathanKingston jonathanKingston left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of 08991632: no blocking findings. Two small robustness nits in the runner.

  • runSectionInChild resolves on the child's 'exit'. Node can emit 'exit' before the last IPC 'message' has been delivered, so a section's memory can occasionally show as — in the summary. Resolving on 'close' (which waits for stdio and IPC to close) avoids that.
  • There's no 'error' listener on the child. If the spawn itself fails, the promise may never settle and the runner hangs rather than naming the section. Resolving with a failed result on 'error' would fix it.
  • Small: the comment "Exit code 134 is a V8 heap OOM (SIGABRT)" doesn't match what the summary shows. An abort reaches the parent as signal: SIGABRT with code: null, which the table already reports as killed SIGABRT.

Checked: with git diff -w, the section bodies are unchanged apart from being wrapped in functions. Loading jsdom and the library lazily keeps the runner process free of jsdom. parseArgs handles the value-less --in-process without swallowing the next flag. forwardedArgs strips the runner-only flags, and NODE_OPTIONS (the per-section heap cap) is inherited.


Generated by Claude Code

@jonathanKingston
jonathanKingston marked this pull request as ready for review November 26, 2026 10:27
Resolve on 'close' so the last IPC memory message is always delivered,
record a failed spawn as a failed section instead of hanging, and correct
the comment: an OOM abort shows as 'killed SIGABRT', not exit 134.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01F6vooHKVSXCabQW89yiiDs
@jonathanKingston
jonathanKingston merged commit 7cf001f into main Nov 27, 2026
7 checks passed
@jonathanKingston
jonathanKingston deleted the claude/project-thread-36pila branch November 27, 2026 01:45
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.

2 participants