Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,18 @@ jobs:
# default Linux shell (`bash -e`, no pipefail) would take `tee`'s exit
# code (0) and stay green, defeating the guard.
shell: bash
# The bench streams several large fixtures through jsdom back to back
# (footnote #110, incremental-scan #111, lazy-quote sections) — and
# jsdom permanently retains the DOMPurify string path's per-call
# DOMParser document (~1 MB per sanitize at bench-sized inputs; it
# survives forced GC, and bare DOMPurify-on-jsdom reproduces it with
# no library code involved — see #231). Thousands of string-path
# sanitizes accumulate multiple GB over one run, so the ceiling must
# clear the whole FIXED-SIZE workload with margin: 6144 sat within
# ~1 GB of the peak and any allocation growth in a PR tipped it into
# OOM (exit 134). jsdom-only — browsers and the sanitizeInto fragment
# path do not retain. The durable fix (per-section subprocesses) is
# tracked in #231.
# no library code involved — see #231). The bench therefore runs each
# section in its own child process, so that retention can no longer
# accumulate across sections: the string-path `fixtures` table peaks
# around 3.6 GB RSS on its own and every other section stays under
# ~400 MB (in one process the run climbed past 4.4 GB, and an earlier
# 6144 MB cap OOM'd with exit 134). NODE_OPTIONS is inherited by every
# child, so this cap now applies per section; it leaves ample room over
# the largest one. The summary table at the end of the output names
# any section that failed and shows each section's peak RSS.
env:
NODE_OPTIONS: --max-old-space-size=12288
run: npm run bench | tee bench-output.txt
Expand Down
12 changes: 12 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,20 @@ each to completion:
```
npm run bench # defaults: iters=5 warmup=2 chunk=8
npm run bench -- --iters 9 --chunk 4
npm run bench -- --section real-document # one section, in this process
npm run bench -- --in-process # every section in one process
```

By default each section (`fixtures`, `scaling`, `footnote-scaling`,
`incremental-scan`, `code-block`, `real-document`, `work-shape`) runs in its own
child process, one after another. jsdom permanently retains memory on every
string-path DOMPurify `sanitize` call ([#231](https://github.com/copse-dev/streaming-markdown/issues/231)),
so in a single process that retention from the string-path `fixtures` table
(about 3.5 GB) carries into every later section. Each section prints a
`memory [...]` line, and the runner ends with a summary of per-section wall
time, exit status and peak RSS, so a section that OOMs or trips its guard is
named and the rest still run.

| Column | Meaning |
| ----------- | ----------------------------------------------------------------- |
| `string ms` | `renderStreamingMarkdown` — full re-render + sanitize each update |
Expand Down
8 changes: 8 additions & 0 deletions docs/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ can hold different policies without bleed (see [#137 / ADR 0003](decisions/0003-
Never write raw `renderMarkdownUnsafe` output to `innerHTML`.
- Provide a sanitizer backend where the native Sanitizer API is absent (Node,
older browsers): the DOMPurify backend. Without one, `renderMarkdown` throws.
Under **jsdom** specifically, each string-path DOMPurify `sanitize` call
leaves memory behind that forced GC does not reclaim (roughly proportional to
the input size; about 1 MB per call at 4 KB inputs). A long-running jsdom SSR
loop should prefer the DOM emitter (`StreamingMarkdownRenderer`, which
sanitizes through the backend's `sanitizeInto` fragment path and barely
retains) or recycle its worker processes. Real browsers and the native
Sanitizer API are unaffected. See
[#231](https://github.com/copse-dev/streaming-markdown/issues/231).
- If you register a mermaid/KaTeX/highlighter backend, you accept its output as
trusted (post-sink). Pin and review those dependencies.

Expand Down
Loading