Skip to content

W4: generic renderers, fallback, cold first view - #594

Merged
neuromechanist merged 36 commits into
feature/issue-586-epic-pipeline-progressfrom
feature/issue-588-w4-renderer
Nov 26, 2026
Merged

neuromechanist merged 36 commits into
feature/issue-586-epic-pipeline-progressfrom
feature/issue-588-w4-renderer

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase W4 of the live quality views (#588, epic #586, nemarOrg/nemar-cli#2324): the generic renderers and the fallback, and the fix for the cold first view from #592.

Reading and checking a view

  • read.ts reads TSV under the C3 grammar and JSON as Internet JSON (I-JSON), with the generic kinds' words.
  • guards.ts holds hand-written guards for the view envelope, every registered kind (the five generic kinds and the five presets), both transforms and both contents. The page runs no JSON Schema engine.
  • The guards replay neuroschema's verdict corpus: 236 cases of view, the histogram content and the ic-classes content.

Building the model

  • kinds.ts is the C2 dispatch. A known kind draws itself; otherwise a known base whose role contract the data meet draws them; otherwise the data show as tables. drawAs never throws.
  • model.ts (buildModel) ports neuroschema's build_model. Before a file is parsed, its declared size is checked against the cap, and then the file's presence, size and SHA-256.
  • Parity: all 269 cases and 18 refusals of kinds-models.v1 pass, compared with Object.is, and so do every pointer snap and every bin location.
  • 21 cases place sensors by name. They wait for W2b's nemar.sensor-labels.v1 (placeByNames), and until then they show the site's word labels_pending.

Renderers

  • tree.ts and render/ are pure functions from a model to an element tree. The server prints it as HTML (toHtml); the page builds elements from it (toDom).
  • One renderer per kind: table, lines, heatmap (cells on a canvas), histogram, scalp maps drawn in the worker, and the fallback.
  • The histogram is one SVG tree for both the server and the page.
  • Each view is a figure with:
    • its figcaption;
    • a role="img" text alternative built from the model;
    • a live readout filled by pointer or keyboard with stored text only;
    • a data table behind details;
    • every file offered for download.
  • Scalp maps have a text row per map and state where their positions came from.

Readouts

  • A readout is a stored cell's text.
  • A scalp map's readout is the hovered sensor's stored value, never a grid cell (markerReadout).
  • The legend shows words, not numbers, because the color axis comes from the interpolated grid.

Contours

  • contourLines is null for maps off screen.
  • Painting calls contoursOf, and so does the export hook for W8 (SensorFieldHandle.drawnMaps()).

Cold first view (#592; the ADR 0137 budget is unchanged)

  • A new prepare request builds a layout's geometry ahead of its maps.
  • SensorFieldClient.warm(layout) runs as soon as the layout is known, while the values download. It starts the worker, prepares the geometry, and draws 72 throwaway maps at full size (one batch of 8 and one of 64).
  • A real draw cancels a warm-up that is still running.
  • sharedSensorFieldClient() gives each page one client. The signal viewer now uses it: it prepares its map's geometry when its placement resolves and cancels its own draws on close, instead of ending the shared worker.
  • The perf step now gates the cold first view, beside the median:
    • each cold run uses freshly imported modules, so no earlier run has warmed the code;
    • the budget is 50 ms for the first maps, 100 ms for the 128-sensor view and 300 ms for the 256-sensor view;
    • the gate also checks that the view's draw found the geometry in the cache.
  • The browser spec warms the worker and gates its first view as well.

website#592 leftovers

  • W4: warm the worker at full size (build the geometry as soon as the layout arrives, and run a full-size draw while the view data download)
  • W4: add a CI gate on the cold first view at 50 / 100 ms, beside the median gate
  • Add a late answer({type:"failure", id:null}) and a late messageerror from a dropped stub, asserting the new worker's draws are unaffected. Removing either current() guard now fails the suite.
  • contourLines is null for maps off screen; everything that needs every contour calls contoursOf
  • COLOR_MAPS_NOTICE (/licenses/quality-views/NOTICE.txt) is linked from the rendered heatmaps and scalp maps
  • The size-gate item with two lazy importers was handled in W3; this PR does not change it.

Review fixes (round 1)

The review found model and guard parity exact. These are the fixes for its Important and Moderate items, with the owner's two rulings.

Size: split the code, keep the 30 KB budget (owner ruling)

  • The guards and the renderer rule (kinds.ts) run in the map worker, through check and check-content requests (SensorFieldClient.checks()). They run on this thread, loaded on demand, only when the worker cannot answer. checks.ts holds the types the page uses.
  • render/index.ts loads each renderer on demand for its model type, so sensor-field-view loads only for scalp maps.
  • The size check now:
    • measures each lazy renderer chunk with the entry's static set;
    • fails if W7 (transforms/, activations.ts) or W8 (export/) modules load with the entry.

Instant cached data meets the budget (owner ruling)

  • warm() needs no layout. It draws 16 maps on a synthetic 64-sensor layout in batches of 8 only, so a real draw waits behind at most one batch of 8.
  • The real geometry is prepared once the layout is known.
  • buildModel fetches a scalp map's layout beside its values. Its onLayout callback hands the page the layout's rows (warmInput) for prepare; these are the same rows as fieldDrawInput, so the prepared geometry is the one the draw finds cached.
    • Tested with a layout that has an EOG row and an n/a place: cacheHits > 0, cacheMisses = 0.
  • The four-map evaluation loop is now a function of its own, so the engine optimizes it within the first view. On M4 a cold 128-map view's maps take about 21 ms, down from 36 to 43. Parity is unchanged.
  • CI now gates the eager case (values arrive at mount) beside the cold and median gates. A draw that arrives in the middle of a warm-up is measured and printed, not gated.

Moderate fixes

  • Builders are keyed by kind@version. A registered kind with no builder draws by its base or as tables.
  • The turbo toggle switches the legend gradient too (qv-legend-turbo, with --qv-turbo-* tokens tested against the lookup table).
  • The legend says "each map is colored on its own range".
  • The heatmap legend prints the stored texts of the smallest and largest cells. Under absmax it shows the sign words and the cell of the largest magnitude.
  • The histogram readout adds the unit for bins by edges.
  • HistogramMark has a text field (the stored text), and the mark is part of the text alternative (markSentence).
  • A heatmap readout test uses a stored text that differs from String(value) (1.50e1).
  • Data tables are built when their details first opens. eagerTables builds them up front for a server-drawn page.
  • Unselected series are drawn at 0.75 opacity: 6.6:1 against the light page and 3.4:1 against the dark one. The aria-live readout is written only when its text changes.
  • Keyboard:
    • the scalp maps have a roving tabindex, so all maps are one tab stop: left and right arrows move between maps, up and down between sensors;
    • the group has no tabindex;
    • each map is role="img" with aria-roledescription="scalp map";
    • the data table stays the screen-reader path. I considered role="application" and did not use it, because it would take over screen readers' own reading keys.
  • A renderer that throws says the view could not be drawn and lists its files below.
  • Spans are computed on halved operands (render/scale.ts), so a span past the largest double never puts NaN or Infinity into SVG.
  • downloadUrl is linked only when it is http(s), blob, or a path on this site. javascript:, data: and every other scheme are shown as text.
  • Corrected: 19 verdict-corpus cases are deferred, not 16.
  • labels_pending is recorded under Deviations: it must not reach production before W2b.

Follow-up: a faster geometry (the geometry store was dropped in round 2)

These changes leave the budget and the meaning of "first maps" (the maps on screen first) as they were.

  • The persistent geometry store (IndexedDB) was tried and removed in review round 2.
    • Once the LU was faster, computing the geometry beat reading it back from real IndexedDB in Chrome. On M4 a repeat visit took 21–46 ms to first maps from storage, against about 19–28 ms when computed.
    • The store also had a silent-corruption path, a possible hang, and up to about 120 MB of disk.
    • The in-memory geometry cache of each worker stays.
  • A symmetric solver is ruled out. The interpolation matrix has a zero diagonal and is indefinite, so neither Cholesky nor an unpivoted LDLᵀ exists, and Bunch–Kaufman pivoting would replace the specified pivot order.
  • The LU now eliminates four rows per pass, in a function of its own. Each entry still gets the same single operation in the same order, so the factors are bit-identical (tested against row-by-row elimination). A cold 256-sensor LU drops from 6.2 to 4.0 ms on M4.
  • G and E now share one row function, so the engine has optimized it on G's rows before it runs over E's many. Bit-identical: G's factors are tested against G built entry by entry.
  • The evaluation matrix is bound by Math.log. Exact reuse of r² can skip at most 24% of the logarithms, which is not worth a cache.

Follow-up 2: the first-visit eager view (owner: keep the budget and the gate)

Runner numbers below come from CI run 45746443761 on 61707f7. Each row gives first maps / whole view as the median of three fresh first views; each run imports the code afresh.

Case Runner 128 Runner 256
Cold 7.6 / 54.2 10.2 / 170.3
Eager, first visit (gated) 37.9 / 81.9 59.1 / 224.0
Eager, repeat visit (with the geometry store, removed in round 2) 23.2 / 79.9 37.7 / 203.2
Mid-warm (printed) 20.1 / 63.9 39.0 / 206.7
Median of 5, warm 22.9 / 64.1 34.6 / 190.2

The 256-sensor first-visit eager runs were 59.1, 59.1 and 60.8 ms. Inside them, building the geometry took 34.1 to 35.6 ms. The gate still fails, by 9 ms. I stopped there, as asked.

What each attempt did

  1. Gate flakiness. The swing from 77 to 102 ms was runner noise, not the code: the whole runner moved with it (the 128-sensor warm median went from 55.6 to 70.2 ms between those runs). The first-view gates now take the median of three fresh first views, with the thresholds unchanged. In this run the three eager runs at 128 sensors were 77.3, 81.9 and 82.5 ms.
  2. LU, four rows per pass in a function of its own. The result is bit-identical (tested against row-by-row elimination). A cold 256-sensor LU went from 6.2 to 4.0 ms on M4.
  3. One row function for G and E. The interpolation matrix's rows warm the function before the evaluation matrix uses it, and the synthetic warm-up's geometry warms it too. The result is bit-identical (tested: G's factors equal those of G built entry by entry).
    • With attempt 2, eager first maps at 256 sensors went from 20.8 to 18.7 ms on M4.
    • On the runner, from 64.1 ms (run 45740436938) and 61.3 ms (run 45743315240) to 59.1 ms.
  4. Splitting the geometry by row blocks. Every map of the first batch reads every inside cell, so the first 8 maps need the whole evaluation matrix before any of them is done. Building it in blocks reorders the work but does not shorten it.
  5. Reusing exact ln(r²) values. I measured on the runner: 666,601 of 872,704 values of r² are distinct, 76.4%.
    • A cache could skip at most 24% of the logarithms, against an evaluation matrix that takes 13.7 ms on the runner: about 3 ms at best, before the cost of the lookups. It cannot close 9 ms.
    • An approximation is ruled out.
  6. A second thread for half the rows. Measured on the runner with a Node worker thread:
    • starting it takes 43.0 ms;
    • half of the rows take 9.0 ms in it, cold;
    • the result is bit-identical.
    • The thread start alone costs more than it could save, so I did not build it. It would also need a second copy of the 11.7 KB worker.
  7. Starting earlier. buildModel already hands the layout to the page (onLayout) as soon as it is read, beside the values, so on a real page prepare overlaps with hashing and parsing the values on the main thread. The gate starts its clock with the values already parsed and runs the worker on the same thread, so this overlap cannot show there.

What remains: about 9 ms at 256 sensors on the runner. Of the geometry's 34–35 ms there:

  • the evaluation matrix takes about 14 ms, spent in its 873,000 Math.log calls;
  • the rest is the LU decomposition and the code the engine has not yet compiled.

I see no further exact speedup inside one thread. The options left are the owner's: measure the eager case on a real page, where the worker has its own thread; accept the 256-sensor first visit; or start the geometry before the panel mounts.

Owner ruling: prepare at page load

The gate.

  • The 256-sensor eager view on a first visit is now printed, not gated.
  • Every other gate is unchanged: the 128-sensor first-visit eager gate, every cold gate and the median gates. The repeat-visit gates went with the geometry store in round 2: without the store, a repeat visit is a first visit.
  • W6 will gate this case as "panel opened after page load": the dataset page fetches the layout in idle time and prepares the geometry before the panel opens.

prepareAhead (src/lib/quality-views/prepare-ahead.ts) preloads what the first screen needs, in idle time. It takes an option bag, so W6 can name exactly the first windows:

  • warm: start the shared map worker;
  • layout: {view, file}: fetch the layout file, check its size and SHA-256, read it, and prepare the geometry from warmInput's rows, keyed by the layout's SHA-256 as the draw is;
  • files: fetch and check the first windows' view files, which the panel's buildModel then reads through preloadedSource without fetching them again;
  • maxBytes and signal.

It is built to stay out of the way:

  • It is idempotent: concurrent and repeated calls fetch and prepare nothing twice.
  • It never throws and shows nothing. A failure leaves nothing behind, and the panel does that work when it opens.
  • Its fetches run at low priority.
  • shouldPreload() turns it off on saveData and on 2G-class connections.
  • It is not wired to any page. Tests cover:
    • a draw with only cache hits after a preload, and a model built with no fetch;
    • idempotence;
    • the byte cap and cancellation;
    • a wrong, missing or offline layout;
    • a worker that cannot start;
    • the connection check.

Review fixes (round 2)

  • The geometry store is gone. The in-memory per-worker cache, the faster LU and the shared row function stay; the reasons are under "Follow-up: a faster geometry" above. With it went the repeat-visit gates: without a store, a repeat visit is a first visit.
  • The worker checks computed presets itself. It loads guards-computed.ts as a lazy chunk of its own, through a dynamic import in the ES module worker (worker.format: "es"; ours is the only worker Vite bundles), and no longer answers unchecked. The page loads local-checks.ts and the guards only when the worker cannot start.
  • The renderer rule's kinds table is written out (KIND_TABLE, held equal to the vendored registry by a test), so the worker carries no registry.
  • The size check gates what a first screen loads, gzipped together:
    • the Spectrum tab (entry, lines and scalp maps) and the Components tab (entry, scalp maps and histogram), each at 30 KB;
    • the worker on its own, and the worker with its lazy chunk, each at 12 KB.
    • The page's own checks, which load only without a worker, are printed and not gated.
  • mountView takes a per-container token and an optional AbortSignal, so a slower, older render never replaces a newer one.
  • A panel opened while a preload fetch is still on its way fetches at its own priority at once. The first bytes that match the declared size and SHA-256 win.
  • Smaller fixes:
    • prepareAhead caps at the registry's bytes per role when it is given no cap;
    • its fetch stops reading past the declared size (readLimited);
    • Reader.prefetch leaves no unhandled rejection;
    • warmInput reads places with the model's own cell reader ("", 0x10 and 1e400 are refused, and -0 reads as 0).
  • Accessibility: lines, heatmaps and histograms carry an aria-roledescription and a keys hint, as the scalp maps do.
  • The reviewer's repros are tests:
    • a fast remount;
    • an aborted mount;
    • a preload fetch that hangs while the panel opens;
    • a preload whose bytes lose to the panel's;
    • the default cap;
    • a response longer than declared;
    • an unhandled prefetch rejection;
    • the cell reader;
    • the size unions, gated in the size check.
    • The corrupted-record repro is moot now that the store is gone.

Measured

First maps / whole view. The runner numbers are from CI run 45750267722 on 9a47bd6, as the median of three fresh first views; M4 is Vitest on the same head.

Case M4 128 M4 256 Runner 128 Runner 256
Cold (gated) 2.8 / 18.5 ms 3.9 / 64.6 ms 5.9 / 30.4 ms 8.8 / 103.0 ms
Eager, first visit 11.2 / 26.9 ms (gated) 18.8 / 80.1 ms (printed) 22.1 / 46.9 ms (gated) 35.4 / 138.2 ms (printed)
Mid-warm (printed) 6.1 / 21.8 ms 13.3 / 74.0 ms 12.2 / 38.5 ms 21.4 / 122.8 ms
  • This run's runner was faster than in earlier runs. In run 45746443761, first-visit eager at 256 sensors took 59.1 ms to first maps.
  • The 256-sensor first-visit eager case stays printed until W6 gates it as "panel opened after page load".
  • In headless Chrome on M4, two runs:
    • at 128 sensors: cold 7.3 / 28.7 ms and eager 20.1 / 45.8 ms;
    • at 256 sensors: cold 13.5 / 77.1 ms and eager 29.5 / 107.4 ms.

Size (check-quality-views-size.mjs, gzipped together; the sum of the files' own gzip sizes in brackets):

What Size Budget
First screen, Spectrum tab (entry, lines, scalp maps) 23.8 KB (25.0) 30 KB
First screen, Components tab (entry, scalp maps, histogram) 24.2 KB (25.3) 30 KB
Worker on its own 10.6 KB 12 KB
Worker with its lazy guards-computed chunk 11.8 KB (12.1) 12 KB
The worker's lazy chunk on its own 1.5 KB —
Page checks without a worker (local-checks with guards-computed), printed only 31.0 KB not gated
  • Each lazy renderer, measured with the entry, stays at 23.0 KB or less.
  • When the worker cannot start, the page checks views itself and goes over the main-thread budget (31.0 KB). That path loads only without a worker, so it is printed and not gated.

Mutations (each must fail the named tests)

The mutation script lives outside the repository; each mutation edits one guarded line, runs the tests and restores the file.

Mutation Result
unknown kind throws instead of falling back caught
renderer throws on a model it does not know caught
scalp-map readout from the interpolated grid caught
lines readout prints a re-computed number, not the stored text caught
pointer reads between rows (floor, not nearest) caught
bin edge off by one: a value on an edge goes to the lower bin caught
bin edge off by one: the last edge is overflow caught
bin labels: the closed bin is not the last caught
dropping the warm-up (warm resolves at once) fails the cold gate caught
dropped worker's onmessage acts (no current() guard) caught
dropped worker's onmessageerror acts (no current() guard) caught
guards: a known kind's schema is not applied caught
prepare builds no geometry (cold gate) caught
worker answers checks for another view caught
worker answers content checks wrongly caught
a registered kind with no builder draws as tables, not by its base caught
the layout is not handed to the page early (onLayout) caught
the layout is not prefetched beside the values caught
warmInput keeps a row with no place caught
warmInput keeps an EOG row caught
data tables built eagerly on the page caught
javascript: download links allowed caught
readout rewritten when its text is the same caught
heatmap legend low end is not the smallest cell caught
histogram mark prints its value again, not its stored text caught
histogram readout drops the unit of bins by edges caught
lines plot overflows to NaN on wide spans caught
every scalp map a tab stop caught
a failed renderer shows tables without saying so caught

| the four-row LU pass changes the operation order | caught |
| G's diagonal is not g(0) = 0 | caught |
| the worker checks computed presets on the envelope alone | caught |
| a stale mount replaces a newer one | caught |
| the panel waits on a hung preload | caught |
| a prefetch rejection is left unhandled | caught |
| warmInput reads cells with Number | caught |
| prepareAhead has no default cap | caught |
| readLimited reads past the declared size | caught |
| drawings lose their role description | caught |
| the worker checks a computed preset without its schemas | caught |

One possible mutation has no test: hard-coding version 1 in the kind@version key. Every registered kind is at version 1 today, so that mutation is not observable.

The warm-up mutation is caught by the cold gate's check that the warm-up drew its 16 maps. The prepare mutation is caught by the same gate's check that the geometry was cached. On the runner the timing is also at the edge: in this run an unwarmed first view drew its first maps in 50.1 ms, over the 50 ms budget. W2 measured the whole unwarmed view at 107 to 137 ms there.

Deviations

  • Placement by name (21 model cases) waits for W2b. The model takes placeByNames; without it, every map shows labels_pending. Those cases still compare drawing, refusal, downloads and stored texts.
    labels_pending must not reach production before W2b: no panel may ship with a scalp map placed by name until nemar.sensor-labels.v1 provides placeByNames.
  • Presets are drawn by their base. The spectrum's maps and preset fields in kinds-models.v1 and the preset-checks.v1 and record-checks.v1 vectors are left to W6.
  • Verdict corpus: 19 cases of dataQuality, the data paper and the dataset document are not replayed. The test names their schemas with their phases (W5/W6).
  • Dispatch is split across two files. The plan names kinds.ts, which holds the registry, the rule and the role contract. Dispatching a built model to its renderer lives in render/index.ts.
  • Heatmap cells go on a canvas. A heatmap may hold 262,144 cells, too many for SVG elements, so the cells are painted one pixel each. Its labels, readout and data table are elements.
  • The viewer only prepares. It draws one map, so it does not run a full warm-up draw.
  • The cold gate assumes the warm-up finishes before the values arrive, which is the owner's design: warm while the data download. The warm-up takes 31 ms (128 sensors) and 50 ms (256) on M4 in Vitest, and 51 to 76 ms in Chrome.

What W5 and W6 need

  • W5:
    • tsv.ts/verify.ts should build on read.ts (TSV, cells, I-JSON) and model.ts's subtleSha256, not repeat them.
    • The dataset summary draws its histograms with histogramSvg(model, mark?) and toHtml, one tree for the server and the page.
    • markedIndex places one recording's value by the edges' rule; NaN marks nothing.
  • W6:
    • Draw a recording's views:
      • build the model with buildModel(view, preloadedSource(fetchFile), {checks: sharedSensorFieldClient().checks(), montage: loadMontage, onLayout});
      • draw it with mountView(container, built, ctx, {client: sharedSensorFieldClient, layoutKey, colors}, signal).
    • mountView ignores a stale mount: a newer mount of the same container, or an aborted signal, wins.
    • Call sharedSensorFieldClient().warm() when the panel mounts. In onLayout, call prepare({layoutKey, ...places}).
    • Import src/styles/quality-views.css in the panel.
    • renderRefusal(word, downloads, ctx) words a ViewRefused.
    • Preset drawings (the spectrum's maps at a frequency, ic-maps' component rows, ic-classes) build on the base models here.
    • Main-thread headroom: see the first-screen unions under Size; each is gated at 30 KB.
  • W6, idle-time preload of the first screen. This is a feature in its own right: people see the first screen sooner, and opening the panel is then just a draw.
    • Trigger: when the dataset page loads, call prepareAhead from requestIdleCallback, after shouldPreload().
    • Scope: only what the first screen of the default recording needs:
      • warm the worker;
      • the layout and its geometry;
      • the files of the first couple of view windows (the views drawn on first open), which include the values of the first on-screen batch of maps.
      • Other recordings, later windows and off-screen components load when the user scrolls, switches tabs or picks another recording.
      • prepareAhead does not draw maps ahead. Drawing the first batch before the panel opens would need a result cache for it, which W6 adds if it wants that.
    • Byte cap: set maxBytes from the files named above (the cap follows the scope).
    • Behavior:
      • never compete with the viewer's own loads (the fetches are low priority; start after the viewer's first loads);
      • pass an AbortSignal that aborts when the user navigates away, and call forgetPreloads() on leaving the dataset;
      • leave nothing visible when it fails.
    • New gate, "panel opened after page load": the panel opens at least one idle period after page load, the values arrive at mount, and the budget is 50/100/300 ms.
  • Worker size: W7's ic-activity transform must be a lazy chunk of the worker, like guards-computed.ts. The size check gates the worker together with its lazy chunks at 12 KB.
  • W8: export reads SensorFieldHandle.drawnMaps(), which already traces contours through contoursOf.

Testing

  • bun run typecheck: 0 errors. bun run lint: clean.
  • Targeted Vitest, all quality-views-* files and eeg-viewer: pass.
  • Mutations: 40, all caught.
  • bunx astro build, then the size check: pass (numbers above).
  • bun run test:quality-views-perf on M4: pass.
  • bun run test:e2e e2e/quality-views-perf.spec.ts: 2 of 2 pass on M4.
  • Full bun run test with every NEMAR_CLI_* variable set: 8,020 passed, 5 skipped. The 6 failures are the expected drift tests against nemar-cli dev.
  • CI run 45750267722 on 9a47bd6: lint, typecheck, the drawing budget and the size step pass. Vitest fails only the same 6 drift tests.

Refs #588, #592, nemarOrg/nemar-cli#2324

Agentic AI tools were used.

TSV and I-JSON readers with the generic kinds' words, and hand-written guards for the view envelope, every registered kind, both transforms and the two contents, replaying neuroschema's verdict corpus (236 cases). Tested: vitest guards file.
Port of build_model: the renderer rule with the role contract, the table, lines, heatmap, histogram and sensor-field models, the fallback, digest checks before parsing, readout snapping and bin location. Held to kinds-models.v1 (269 cases, 18 refusals); 21 cases placed by name await W2b. Tested: vitest models file.
kinds.ts holds the registry, drawAs and the role contract (C2); model.ts builds models. No behavior change; models test passes.
Element-tree renderers for table, lines, heatmap, histogram (one SVG tree for server and page), scalp maps on the worker and the fallback, each a figure with caption, text alternative, readout from stored text, data table and downloads; color maps notice linked. The viewer's map-frame helpers move to render/map-frame.ts. Tested: vitest quality-views files and scalp-map.
A prepare request builds a layout's geometry ahead of its maps; SensorFieldClient.warm prepares and draws a full-size throwaway set while the values download, and a real draw cancels a warm-up still running. sharedSensorFieldClient gives a page one worker. Tests for late failure and messageerror events from a dropped worker (website#592). Tested: vitest worker file.
The live scalp map draws through sharedSensorFieldClient, prepares the geometry when its placement resolves with the panel open, and cancels its own draws on close instead of ending the shared worker. Tested: vitest eeg-viewer.
The perf step gates the first view on freshly imported code at 50/100 ms (128) and 300 ms (256), warmed while the values download, and checks the geometry was cached; the browser spec warms and gates its first view too. Tested: test:quality-views-perf and the e2e spec on M4.
The entry build measures the model and renderers with the client. The model takes map outcomes as an option and loads the layout projection on demand, so the interpolation stays in the worker: 27.7 KB of 30. Tested: astro build plus size check, vitest models and render.
markerReadout is what a pointer or key on a map's marker shows; the render test holds it to each plotted sensor's stored text on a worker-drawn map. Tested: vitest render file.
AGENTS.md lists read, guards, kinds, model, tree and render, the stylesheet and the shared, warmed client; the CI perf step's comment names the cold first view. Docs only.
Biome formatting only. Tested: bun run lint.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

astro check lost the sensor-field narrowing inside a closure in the render test. Tested: bun run typecheck, vitest render file.
The guards and the renderer rule run in the map worker (check and check-content requests; on this thread only when the worker cannot answer). Builders are keyed by kind@version. buildModel fetches a scalp map's layout beside its values and hands warmInput's rows to onLayout for prepare. warm() takes no layout (a synthetic 64-sensor one) and draws 16 maps in batches of 8. Tested: vitest checks, models, worker.
The four-map, two-cell loop over the evaluation matrix is its own function, so the engine optimizes it within a page's first view: a cold 128-map view's maps take about 21 ms on M4 instead of 36 to 43. Parity unchanged. Tested: vitest sensor-field parity, worker, models.
render/index.ts loads each renderer on demand per model type; data tables are built on first open; heatmap legend from stored texts; histogram mark text and unit in readouts; turbo legend; per-map range note; roving tabindex over scalp maps; readout spoken only on change; overflow-safe plot spans; download links only by http(s), blob or site paths; a failed renderer says so and lists the files. Tested: vitest render.
The perf step gates cold (warmed on mount, geometry prepared from the layout) and eager (cached data at mount) first views at 50/100 ms (128) and 300 ms (256), and prints a draw arriving mid-warm-up; the browser spec times all three. Tested: test:quality-views-perf and the e2e spec on M4.
Each lazy renderer chunk is measured with the entry's static set against the main-thread budget, and W7/W8 modules (transforms/, activations.ts, export/) fail the check if they load with the entry. Tested: astro build plus the size check.
AGENTS.md and the CI perf comment follow the review's changes. Docs only.
Without onLayout too. Tested: vitest checks file.
Each entry still gets the same one operation in the same order, so the factors are bit-identical (tested against the row-by-row elimination); the 256-sensor LU drops from about 5.2 to 3.3 ms on M4. Tested: vitest linalg, sensor-field parity.
The worker reads a geometry from IndexedDB before computing it (key: layout SHA-256, algorithm version, SHA-256 of the exact places and usable rows), checks it, and stores new ones after the draw answers; 16 layouts LRU; blocked storage only means computing. Stored geometries draw the computed maps bit for bit. Tested: vitest geometry-store, worker.
The perf step gates the eager view of a repeat visit (geometry read back from the earlier visit's storage) beside the first-visit eager, cold and median gates; the browser spec checks real IndexedDB reads and bit-identical maps. Tested: test:quality-views-perf, e2e spec on M4.
The schemas of nemar.ic-activity, nemar.signal-window and nemar.ic-activity.v1 move to guards-computed.ts. The worker answers unchecked for those views and the page checks them in local-checks.ts, a lazy chunk, so the map worker with its geometry store stays within 12 KB (11.7). The size check measures the lazy check chunks too. Tested: vitest quality-views, astro build plus size check.
And AGENTS.md names guards-computed and local-checks. Tested: vitest guards.
The elimination below each pivot is its own function, four rows per pass over the pivot row; each entry still gets the same operation in the same order, so the factors are bit-identical (tested). A cold 256-sensor LU drops from about 6.2 to 4.0 ms on M4. Tested: vitest linalg, sensor-field parity.
The interpolation and evaluation matrices fill their rows with one function (g(0) = 0 is the diagonal's 0), so the engine has optimized it on G's rows before E's many, and a synthetic warm-up's geometry warms it too. Parity unchanged. Tested: vitest sensor-field parity, worker, geometry store.
Cold, eager and repeat-visit first views are each run three times on freshly imported code and gated by their median at the same 50/100/300 ms; each run prints the draw's geometry and map times. Printed probes measure exact r2 reuse and a second thread for half the evaluation matrix. Tested: test:quality-views-perf on M4.
The interpolation matrix's factors equal those of G built entry by entry with a zero diagonal, on every drawn vector case. Tested: vitest geometry store.
prepareAhead warms the shared worker, fetches and checks a scalp map's layout and prepares its geometry, and fetches and checks the first windows' view files for preloadedSource; byte cap, AbortSignal, low-priority fetches, shouldPreload for data-saving and 2G links; idempotent, never throws. Measured in the size check. Tested: vitest checks.
By the owner's ruling the dataset page prepares the geometry at page load; W6 gates that case as panel opened after page load. Every other gate is unchanged. Tested: test:quality-views-perf on M4.
Computing now beats reading real IndexedDB, and the store had a silent-corruption path, a hang and up to ~120 MB of disk; the in-memory per-worker cache stays, and so do the faster LU and shared row function (G's bit test kept). The worker checks computed presets itself, loading guards-computed.ts as its own lazy chunk (ES module workers in astro.config and the size build), so it never answers unchecked. Repeat-visit gates go; first-visit eager at 256 stays printed. Tested: vitest quality-views, perf on M4.
The Spectrum (entry, lines, scalp maps) and Components (entry, scalp maps, histogram) first screens are gated at 30 KB gzipped together, and the worker with its lazy computed-schema chunk at 12 KB; the page's own checks, loaded only without a worker, are printed. The renderer rule's kinds table is written out (held to the registry by a test) so the worker carries no registry. Tested: astro build plus size check, vitest kinds and checks.
mountView takes a per-container token and an optional AbortSignal, so a slower, older render never replaces a newer one; lines, heatmaps and histograms carry an aria-roledescription and a keys hint as scalp maps do. Tested: vitest render (fast remount, abort, hints).
A panel opened during a preload fetches at once and the first verified bytes win; prepareAhead defaults its cap to the registry's bytes per role and its fetch stops reading past the declared size; Reader.prefetch leaves no unhandled rejection; warmInput reads places with the model's cell reader. Tested: vitest checks (hung preload, losing preload, cap, readLimited, unhandled rejection, cells).
Biome formatting only.
@neuromechanist
neuromechanist merged commit 25d9aef into feature/issue-586-epic-pipeline-progress Nov 26, 2026
3 of 4 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-588-w4-renderer branch November 26, 2026 03:42
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.

1 participant