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

+36 -10
View File
@@ -1,12 +1,17 @@
// Main thread of the R4 measurement page (R4.2e). Compiles the module once
// Main thread of the R4 measurement page (R4.2e, R4.3a). Compiles the module once
// (`WebAssembly.compileStreaming`), routes a picked file as HomeRoute does
// (first KiB: PDF magic, JSON object or `.json` name), then runs each import
// in a module worker created for it (plan §B.1.5): the compiled Module
// posted by structured clone (or, when an engine refuses the clone, the
// worker fetches the URL, and the refusal is recorded), the File and the
// sheet bundle text posted on `ready`, `terminate()` in every case.
// sheet bundle text posted on `ready`, `terminate()` in every case. The
// worker's read path is `stream` (R4.3a, default) or `arrayBuffer` (R4.2e),
// per call or for the page through `?read=arrayBuffer`. Every `error` and
// `messageerror` event of a worker is recorded with its text, the first one
// settles the run.
//
// window.r4Import(fileOrBytes, bundleJson, mode = 'auto' | 'pdf' | 'copy')
// window.r4Import(fileOrBytes, bundleJson, mode = 'auto' | 'pdf' | 'copy',
// readPath = 'stream' | 'arrayBuffer')
// window.r4Proof('ceiling' | 'cap_off', bundleJson, file?)
// window.r4LastResult, window.r4Page (CSP violations, long tasks, compile)
const WASM_URL = '/pkg/faunosteo_wasm_bg.wasm'
@@ -17,6 +22,11 @@ const LIMITS = { pdfBytes: 50 * MiB, copyBytes: 16 * MiB }
const TIMEOUTS = { startMs: 10_000, taskMs: 120_000 }
const SNIFF_BYTES = 1024
const PDF_MAGIC = '%PDF-'
const READ_PATHS = ['stream', 'arrayBuffer']
const PAGE_READ_PATH =
new URLSearchParams(location.search).get('read') === 'arrayBuffer'
? 'arrayBuffer'
: 'stream'
const page = {
csp: [],
@@ -130,6 +140,7 @@ class WorkerRun {
this.transfer = null
this.cloneError = null
this.workerCsp = []
this.events = []
this.done = new Promise((resolve) => (this.resolve = resolve))
}
@@ -140,10 +151,8 @@ class WorkerRun {
return this.settle(this.failure('start', 'worker_unavailable', error))
}
this.worker.onmessage = (event) => this.onMessage(event.data)
this.worker.onerror = (event) =>
this.settle(this.failure(this.phase(), 'worker_error', errorText(event)))
this.worker.onmessageerror = () =>
this.settle(this.failure(this.phase(), 'messageerror', null))
this.worker.onerror = (event) => this.onEvent('worker_error', event)
this.worker.onmessageerror = (event) => this.onEvent('messageerror', event)
this.arm(TIMEOUTS.startMs, 'start')
this.postInit()
return this.done
@@ -153,6 +162,14 @@ class WorkerRun {
return this.readyAt === null ? 'start' : 'task'
}
/** Every error / messageerror event kept with its text; the first settles. */
onEvent(kind, event) {
const text = kind === 'worker_error' ? errorText(event) : event.type
const at = Math.round(now() - this.createdAt)
this.events.push({ kind, phase: this.phase(), text, atMs: at })
this.settle(this.failure(this.phase(), kind, text))
}
failure(phase, kind, error) {
const text = typeof error === 'string' ? error : error && describe(error)
return { outcome: 'failed', phase, kind, error: text ?? null }
@@ -239,6 +256,7 @@ class WorkerRun {
cloneError: this.cloneError,
readyLinearBytes: this.readyLinearBytes ?? null,
workerCsp: this.workerCsp,
workerEvents: this.events,
}
}
}
@@ -246,19 +264,27 @@ class WorkerRun {
const asFile = (input) =>
input instanceof Blob ? input : new File([input], 'input.pdf')
async function r4Import(input, bundleJson, mode = 'auto') {
async function r4Import(input, bundleJson, mode = 'auto', readPath) {
const calledAt = now()
const file = asFile(input)
const route = mode === 'auto' ? await routeOf(file) : mode
const { module } = await window.r4Ready.compiled
const task = { type: 'task', route, file, sheet: bundleJson, limits: LIMITS }
const path = READ_PATHS.includes(readPath) ? readPath : PAGE_READ_PATH
const task = {
type: 'task',
route,
file,
sheet: bundleJson,
limits: LIMITS,
readPath: path,
}
const run = new WorkerRun({
url: IMPORT_WORKER,
protocol: 'import',
module,
task,
})
const result = { route, ...(await run.start()) }
const result = { route, readPath: path, ...(await run.start()) }
result.pageMs = now() - calledAt
window.r4LastResult = result
document.getElementById('status').textContent = JSON.stringify(result)