test(tests): R4.3a browser re-measure of large files, leak series, WebKit repetition (stream sink, BYOB)

Streaming into FileBytes removes the file's JavaScript copy in Chromium and Firefox
(50 MiB: 65 and 67 MiB summed growth against 56 and 79 for the TypeScript); WebKit keeps
about 180 MiB for any file read inside a worker (272 against 76), a main-thread BYOB read
feeding the worker's sink measured at 106. Corpus 666/678 on the stream path. Leak series
(3 engines × 3 documents × 3 repetitions): Chromium ≤ 0.5 MiB over the last 5, Firefox
within ±3 (idle only), WebKit copy +13 then level (12-import series −2.3). 20 dense
imports in WebKit: no worker error event.
This commit is contained in:
bchanot committed 2026-10-18 18:50:47 +02:00
1 parent 8924d50edf
commit 49591c53cd
14 files changed
+3002 -387

No files matched your search

+90 -21
View File
@@ -1,18 +1,20 @@
# Browser harness (R4.1e, R4.2e)
# Browser harness (R4.1e, R4.2e, R4.3a)
Measures the application in real browser engines (Chromium, Firefox, WebKit)
through Playwright: the TypeScript baselines of R4 (export and import time
and memory, plan `.claude/tasks/plans/2026-10-17-rust-r4-pdf-core.md` O12,
§B.3, §B.4, §B.8) and the browser columns of the O9 inflate oracle. Since
R4.2e it also measures the Rust import in a disposable module worker on the
baseline's perimeter, its hostile classes and its memory protections.
baseline's perimeter, its hostile classes and its memory protections; since
R4.3a, the worker's two read paths on the large files and the leak series.
> **Watchdog caveat.** Every browser runs under a 4 GiB RSS watchdog that is
> **not a guaranteed memory limit**. It samples every 50 ms, so a faster
> allocation can overshoot the ceiling before the kill; summed VmRSS counts
> shared pages once per process; a process outside the browser's tree is not
> seen. A run it stops is recorded as `stopped_by_ceiling`, which is a
> result, not a harness failure.
> result, not a harness failure. The same sampling misses a peak shorter
> than 50 ms (an import that reads, peaks and ends within one interval).
## Prerequisites
@@ -44,25 +46,34 @@ baseline's perimeter, its hostile classes and its memory protections.
All from the repository root.
| Command | What it does |
| -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| `node scripts/browser/serve.mjs [--port 4173] [--csp with\|without]` | serves `apps/app/dist` on `127.0.0.1` until Ctrl-C |
| `node scripts/browser/ts-baseline.mjs` | export then import baseline, one file `results/<date>-ts-baseline.json`, tables on stdout |
| `node scripts/browser/export-baseline.mjs` | export baseline only (`results/<date>-export.json`) |
| `node scripts/browser/import-baseline.mjs` | import baseline only (`results/<date>-import.json`) |
| `node scripts/browser/inflate-verdicts.mjs` | O9 browser columns → `crates/core/tests/oracles/r4/inflate.browsers.json` |
| `node scripts/browser/summarize.mjs <results.json>` | prints the markdown tables of a results file |
| `node scripts/browser/serve.mjs --r4` | the same server, plus the R4 import page at `/r4/` and the module builds |
| `node scripts/browser/r4-import.mjs` | Rust import in a module worker, `results/<date>-r4-import.json`, tables on stdout |
| `node scripts/browser/compare-imports.mjs <ts.json> <r4.json>` | TS baseline vs Rust import: durations, RSS growth, per-file outcome agreement |
| Command | What it does |
| -------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| `node scripts/browser/serve.mjs [--port 4173] [--csp with\|without]` | serves `apps/app/dist` on `127.0.0.1` until Ctrl-C |
| `node scripts/browser/ts-baseline.mjs` | export then import baseline, one file `results/<date>-ts-baseline.json`, tables on stdout |
| `node scripts/browser/export-baseline.mjs` | export baseline only (`results/<date>-export.json`) |
| `node scripts/browser/import-baseline.mjs` | import baseline only (`results/<date>-import.json`) |
| `node scripts/browser/inflate-verdicts.mjs` | O9 browser columns → `crates/core/tests/oracles/r4/inflate.browsers.json` |
| `node scripts/browser/summarize.mjs <results.json>` | prints the markdown tables of a results file |
| `node scripts/browser/serve.mjs --r4` | the same server, plus the R4 import page at `/r4/` and the module builds |
| `node scripts/browser/r4-import.mjs` | Rust import in a module worker, `results/<date>-r4-import.json`, tables on stdout |
| `node scripts/browser/compare-imports.mjs <ts.json> <r4.json>` | TS baseline vs Rust import: durations, RSS growth, per-file outcome agreement |
| `node scripts/browser/r4-large-files.mjs` | files of 10 MiB and more, both read paths, `results/<date>-r4-large-files.json`, table |
| `node scripts/browser/r4-leak-series.mjs` | leak series per engine and document, WebKit repetition, `results/<date>-r4-leak-series.json` |
Options of the baseline scripts: `--engines chromium,firefox,webkit` (default
all three), `--out <file>`, `--reports demo,L,CAP` (export runs to keep),
`--groups base,r3,step6,tolerance,read` (import groups to keep). Progress goes
to stderr, the tables to stdout. `r4-import.mjs` takes `--engines`, `--out`,
`--groups`, plus `--sections import,hostile,repeat,proofs`, `--classes <id,…>`
(hostile classes to keep) and `--scratch <dir>` (where the hostile files and
(hostile classes to keep), `--read stream|arrayBuffer` (the worker's read
path, default `stream`) and `--scratch <dir>` (where the hostile files and
the module copies live during the run, default the OS temporary directory).
`r4-large-files.mjs` takes `--engines`, `--paths stream,arrayBuffer`, `--ts
<ts-baseline.json>` (default the newest `results/*-ts-baseline.json`),
`--scratch`, `--out`. `r4-leak-series.mjs` takes `--engines`, `--sections
leak,webkit-repeat`, `--reps 3`, `--imports 6`, `--webkit-imports 20`,
`--read`, `--scratch`, `--out`. The results files are written before the
tables are printed.
## The server (`serve.mjs`)
@@ -170,10 +181,31 @@ file as HomeRoute does (first KiB: `%PDF-`, a JSON object, a `.json` name).
Each import then gets its own module worker: the compiled `Module` posted by
structured clone (an engine that refuses the clone is recorded and the
worker fetches the URL instead), the `File` and the sheet bundle text posted
on `ready`, the file read in the worker, the size re-checked (50 MiB PDF,
16 MiB copy), one `SheetHandle`, `import_pdf` or the strict `TextDecoder`
then `draft.restore`, one result string parsed on the main thread,
on `ready`, the size re-checked before any read (a PDF over 50 MiB answers
`invalid_pdf`, a copy over 16 MiB `invalid`), the file read in the worker,
one `SheetHandle`, one result string parsed on the main thread,
`terminate()` in every case. Timers: 10 s until `ready`, 120 s for the task.
The worker reads the file one of two ways (`readPath`, per call or for the
page with `/r4/?read=arrayBuffer`):
- `stream` (default, R4.3a): `file.stream()` pushed chunk by chunk into a
`FileBytes(file.size)` sink in linear memory, then `import_pdf_bytes` or
`restore_copy_bytes`, which consume the sink (the core does the copy's
strict UTF-8 decode, BOM and value budget). A BYOB reader reads into one
reused 1 MiB buffer, so no read leaves a dead chunk for the GC; a stream
that refuses BYOB is read with its default reader, each chunk dropped once
pushed; an engine without `stream` reads the file whole and pushes it
once. A read that ends short of `file.size`, or a push past it, is a
`read` failure, never a PDF verdict.
- `arrayBuffer` (R4.2e): one ArrayBuffer of the file, `import_pdf` (the glue
copies it into linear memory) or the strict `TextDecoder` then
`draft.restore`, both alive during the call.
The result's `diag` names the path asked and the one that ran (`readVia`:
`stream-byob`, `stream-default`, `arrayBuffer-fallback`, `arrayBuffer`),
the chunk count and the largest chunk. Every `error` and `messageerror`
event of a worker is recorded with its text (`workerEvents`); the first one
settles the run as a `failed` outcome, none is suppressed.
The script copies `pkg/` and `pkg-proofs/` at start and serves the copies,
so a rebuild during the run cannot mix two modules; the results name the
@@ -213,6 +245,39 @@ outside the `import` section; idle is not a GC, so their deltas are
indicative only. Every run records the CSP violations seen by the page and
by the worker (`securitypolicyviolation`), page errors and console errors.
### Large files (`r4-large-files.mjs`)
The inputs of the import baseline's `read` group of 10 MiB and more (sizes
from the files or their `.gen.json` descriptions), plus the hostile classes
`file-50mib`, `CAP-envelope`, `dense-numbers-16mib` and
`dense-numbers-copy-16mib`, each imported once per engine and per read path
(`stream`, `arrayBuffer`), the two paths of a file back to back and their
order alternated from one file to the next. Same row as `r4-import.mjs`: page
and Node-clock durations, summed and content RSS before, peak and right
after, linear memory, chunks; a fresh context per run, the worker
terminated. The settled level before and after each run is a forced GC + 1 s
in Chromium (the after-GC delta) and 5 s idle in Firefox and WebKit. The
table puts beside both paths the TS baseline's growth for the same file
(peak minus the level before the file is set, Node-clock duration), copied
into the results file (`tsBaseline`).
### Leak series (`r4-leak-series.mjs`)
Per engine, per document (the L envelope, the 16 MiB dense numbers refused
by the value budget, the 16 MiB rescue copy), three repetitions, each in ONE
page: the file set once, the start level, one import (the init cost, counted
apart), six more imports, the worker terminated after each, 2 s idle, a
reading after each import, then 5 s idle and a final reading. Chromium forces
a GC (CDP) and waits 1 s before every reading; Firefox and WebKit are read
after idle only, which is not a GC, so their levels are indicative. The row
keeps the content and summed levels, the init delta (L1 − L0), the six
per-import deltas, the recurring growth over the last five imports
(L7 − L2) and the same at the final reading, against the 10 MiB tolerance of
BDR-058, and the series peak. `webkit-repeat`: WebKit, one page, 20
consecutive imports of the 16 MiB dense document, a worker per import; the
outcomes, every worker `error` / `messageerror` event with its text, the
content level after each import and the series peak.
### Comparison (`compare-imports.mjs`)
Pairs the runs of a TS baseline file and an R4 file by engine and file.
@@ -243,14 +308,18 @@ itself.
scripts/browser/
├─ serve.mjs, ts-baseline.mjs, export-baseline.mjs, import-baseline.mjs
├─ inflate-verdicts.mjs, summarize.mjs
├─ r4-import.mjs, compare-imports.mjs
├─ r4-import.mjs, compare-imports.mjs, r4-large-files.mjs, r4-leak-series.mjs
├─ r4-import-page/ index.html, main.js (compile, routing, one worker per
│ import), worker.js (the import worker), proofs-worker.js
│ import, worker events), worker.js (the import worker, both read
│ paths), proofs-worker.js
├─ lib/ playwright (load, launch under the watchdog, close), watchdog + its
│ sampler thread, proc (/proc reads), page-probes (init scripts),
│ harness (CLI, results file), summary (tables), app-build, host,
│ inputs, stats, async, paths; R4.2e: import-inputs (the baseline's
│ file set), core-module (bundle, module facts and copies, Node
│ instance), hostile-classes (budget-suite builders), r4-summary
│ instance), hostile-classes (budget-suite builders), r4-summary;
│ R4.3a: r4-runs (page, import race, settled levels, run row, engine
│ loop, prepared module run), r4-memory-summary (large-file and leak
│ tables)
└─ results/ raw results files
```