docs(docs): RUST.md §10.5 draft of the R4.3 worker (amendment to B.1.5, messages, memory, leak series)

This commit is contained in:
bchanot committed 2026-10-18 19:00:24 +02:00
1 parent e659924ec0
commit e0127b0726
1 file changed
+72
+72
View File
@@ -1283,3 +1283,75 @@ process after the worker is terminated and a GC forced):
Not measured: real devices and browsers (J1), forced GC in Firefox and
WebKit, CPU throttling, the hostile classes on the TS side, the negative
CSP proof (without the keyword), the application's own worker (R4.3).
### 10.5 R4.3: the import in a disposable worker (2026-10-18, application switched)
What runs where (`apps/app/src/core/worker/`, plan §B.1.5 with one amendment
below): the page refuses up front when its own engine stopped, routes on the
first KiB and checks the sizes as before, then creates a module worker
(`import.worker.ts`, the glue bundled statically into a hashed `/assets/`
chunk that `script-src 'self'` allows), posts the task with the bundled
sheet text and its runtime's compiled `WebAssembly.Module` (structured
clone: 236 of 236 workers in R4.2e, every engine), reads the file in 1 MiB
chunks with a BYOB reader and streams them to the worker (`chunk` /
`ack` with the buffer transferred both ways: the page holds one chunk, the
worker's `FileBytes` sink the only whole copy, no byte parsed on the page),
posts `end`, and reads the first of `result`, `failed`, an `error` event
(never masked), the start timer (10 s to `ready`), the task timer (20 s,
paused while the page is hidden; the J1 hypothesis) or a cancel; the worker
is terminated in every case. The worker answers `ready`, builds its
`SheetHandle`, runs `import_pdf_bytes` or `restore_copy_bytes` (strict
UTF-8, one BOM, the OD-3 budget) and answers the core's envelope; every
throwable becomes one `failed` with its phase and kind. The page then loads
its own index for `hydrateImport`, as before; a result is dropped when the
session changed since the pick, leaving Home cancels the import, one import
runs at a time, and the worker chunk is prefetched once the editor has
loaded the engine so an offline import still starts.
Amendment to §B.1.5 item 3 ("the `File` itself, never read on the main
thread"): the file is read on the page, chunk by chunk, because reading a
file inside a WebKit worker costs about 180 MiB of content-process RSS
whatever the method (`arrayBuffer`, default stream, BYOB; 14 MiB on the
page, 13 to 15 in Chromium and Firefox workers), measured in R4.3a on a
50 MiB file: worker read 272 to 316 MiB against 76 for the TypeScript, page
read feeding the worker's sink 106. The isolation stays: untrusted bytes are
parsed in the worker only; the page moves buffers.
Messages (§B.1.8, OD-5), pinned on every file of the frozen corpora by
`routes.HomeRoute.messages.test.tsx` through the real worker logic
in-process: O8 51 PDFs (47 as R3, the four declared), the stored O7 inputs
(over 130), the O2, O3 and Step 5 reference PDFs (editor), the 612-leaf
export (editor); a worker trap, a timeout or a file the page cannot read is
« Erreur de lecture du PDF. », a worker that cannot start is the engine
message, and the page's own runtime stays `ready` after a worker trap.
Suites: handler and client in-process (`core.importWorker`,
`core.importClient`), the six existing Home / core-failure suites migrated
to the real worker logic (53 cases, titles kept), 458 app tests.
Memory (R4.3a, measurement page, three engines, summed / content RSS
growth MiB, TS · worker read · page read where measured):
| File | Chromium | Firefox | WebKit |
|---|---|---|---|
| 50 MiB file, attachment at the end | 56/55 · 65/66 · page read pending | 79/59 · 67/65 · pending | 76/60 · 272/251 · 106 (probe) |
| 16 MiB rescue copy | – · 33/33 | – · 29/30 | – · 133/124 |
| 16 MiB dense numbers | – · 33/33 | – · 32/30 | – · 108/98 |
| CAP envelope | – · 16/17 | – · 19/16 | – · 41/37 |
The streaming sink alone removed the file's JavaScript copy in Chromium and
Firefox (within 9 MiB of the TypeScript, or below it); the rescue copy drops
from 52 to 20 MiB of linear memory and reads faster (221 → 128 ms in
Chromium). The page-side read of the application build is measured in the
R4.3d run below.
Leak series (R4.3a measurement page, content RSS, init = first import):
Chromium (GC forced) init 9 to 11 MiB, growth over the next five within
±0.5 on the three documents, three repetitions each; Firefox (idle only)
init 5 to 7, swings of ±3 from its own GC timing, final idle delta 0;
WebKit (idle only) init 17 to 38, the 16 MiB documents warm up in one or two
steps (dense +17 to +20 once; copy +12 to +15 then +17 to +19) and drop 3 to
6 MiB at the fifth import, so the copy misses the 10 MiB window as written
(+12.7 to +14.1 over the last five of six) while a 12-import series levels
off (−2.3 over its last five). Twenty consecutive dense imports in WebKit:
all refused, no worker `error` event (the one seen in an R4.2e smoke run did
not reproduce).