Skip to content

perf(lynx): read a program's listeners from the run, not by searching for them - #214

Merged
Huxpro merged 5 commits into
new-lynxfrom
feat/lynx-program-announcement-run
Aug 27, 2026
Merged

Huxpro merged 5 commits into
new-lynxfrom
feat/lynx-program-announcement-run

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

Issue #163, slice C18 — the first reduction in off_boundary's publish
bucket rather than another attribution of it.

The first-screen renderer announces a compiled program's event sites in one
contiguous pass, in site order. The applier then threw that order away: for
every site of every row it searched the whole announcement for the host
(eventsByHost.get), and then that host's list for the type (.find with a
fresh closure), to recover a position it had just been handed.

C13 priced that search at 38 ms of main-thread script at 30,000 rows, net
of the fold hazard its arm controlled for (stages/results/c163-c13-lookup-30000.md:
program mount 208.9 → 167.0 for the positional arm). Measured against this
head it is 49.7 ms — see Validation.

So the renderer now records where its own announcements begin and how many
there are, and the mount walks that run alongside the sites. The cursor
advances only when an announcement is claimed, which is what leaves a site
whose handler came through undefined open without shifting the sites after it
onto the wrong listeners.

Why this does not weaken anything

The search was never a check — a site it failed to find silently installed no
listener. Replacing it changes nothing about that, and the run reads the same
source of truth as before (envelope.events itself, not a copy), so nothing
can drift between what the background installs and what this side binds.

It also adds two faults where there was silence:

  • an announcement left inside the run that no site claimed is a listener the
    background installed and this side bound to nothing; and
  • a node carrying eventsAt without eventsCount, which reads as an empty run
    and would paint the whole program with no listeners at all. That one is this
    diff's own defect, found by reviewing it after the first measurement had
    already been taken, and it is the third commit.

freezePlanNode gains the precondition the addressing rests on — (node, type)
names at most one site. prepareUniversalTemplateProgram already rejects a
program that would violate it (packages/octane/src/universal-template-program.ts:742),
so this is that guarantee restated where the runtime can see it, for plans that
do not come from the compiler. Freezing runs once per plan, so it costs nothing
per row.

A tree built by hand carries no run and gets the search unchanged, so the
exported applier keeps its contract. A test holds the two readers to the same
answer for the same tree and envelope.

Changes

  • packages/lynx/src/main-renderer.ts
    • freezePlanNode refuses a program plan binding two events of one type to
      one node.
    • FirstScreenProgram carries eventsAt/eventsCount; collectFirstScreenEvents
      fills them around its own announcing loop, before the walk descends.
  • packages/lynx/src/core/host-driver.ts
    • LynxFirstScreenDirectNode carries the same two fields, both optional.
    • mountProgram walks the run with a cursor and verifies each claim, falling
      back to the search when a node carries no run, faults on an unclaimed
      announcement, and refuses a node carrying half a run.
  • benchmarks/lynx-table/
    • the A/B records under stages/results/, and the README section that reads
      them.

Validation

  • pnpm format:check
  • pnpm typecheck — scoped: pnpm typecheck:files over the four changed
    files. Clean for the two src/ files and first-screen-direct.test.ts.
    main-renderer.test.ts reports two TS2554 errors at lines 487–488;
    both reproduce identically with this branch's changes stashed, so they
    are pre-existing and not this diff's.
  • pnpm test — repo-wide, every project in vitest.config.js including
    octane-prod, exit code 0.
  • targeted tests: the whole lynx project, 43 files / 639 tests, green.
  • pnpm format:files over the four changed files — all unchanged.
  • pnpm sync — clean.

Every new test was watched failing. Six deliberate breakages of the
implementation, each caught:

mutation caught by
cursor advances once per site, not once per claim leaves a site nothing was announced for open…, installs what the search installs…
the cursor claims an announcement without checking its type same two
the run is never checked for an announcement nothing claimed faults when the run carries an announcement no site claimed
the renderer closes the run after descending into the hole reads the program's own listeners and leaves its hole's members alone
half a run is accepted refuses a node carrying half a run rather than painting it without listeners
a plan may bind two events of one type to one node refuses a compiled program whose tables name nodes it does not make

The fourth mutation survived the first four tests, because all of them hand the
applier a tree they built themselves with the run written by hand — none ran
collectFirstScreenEvents at all. The second commit is the end-to-end test
that closes it.

Measured

Two 30,000-row bundles in one window, --control-dist c18, n=15, AB/BA,
through stages/mts-profile.mjs. stages/results/c163-c18-lookup-30000.json.

main-thread script control, the search treatment, the run Δ
program mount 246.3 [219.9–300.2] 196.6 [179.9–225.3] −49.7
named total 497.0 [445.1–553.4] 447.4 [420.4–489.7] −49.6
all frames 522.4 [465.3–588.8] 472.5 [446.6–516.1] −49.9

The whole movement is in program mount, which is where the search lived.
Nothing else moves outside its own interval: applier walk's +5.7 is the
largest of the rest and its two intervals still overlap over 26.8–29.6.

An earlier run of the same A/B against the same control, on this head before
its third commit, replicates it: program mount 242.4 → 194.1 (−48.3), all
frames 509.5 → 467.2. stages/results/c163-c18-run-30000.json is kept for
that reason rather than discarded as superseded.

The control arm's digest is 381fe0ab988a479c — byte-identical to the
octane-mts-program bundle every C14–C17 record measured. Bundles: control
520,098 B, treatment 520,964 B / 9edb29cf145c659a.

These milliseconds are the profiler's, not the wall clock's. No FCP or
papi-run.mjs wall measurement has been taken against this diff.

envelope.events is unchanged — same entries, same order, same bytes — and the
run is two integers on a main-thread-local node, so oracle clause 2 is
untouched by construction
rather than by measurement.

Risk / follow-ups

  • eventsByHost is still built over the whole envelope, and after this change a
    program's bindings in it are read only by the fallback. At 30,000 rows that is
    60,000 map insertions and tuple allocations whose only remaining consumer is a
    branch the renderer never takes. Skipping them needs the map to know which
    bindings belong to programs; a later slice, not this one.
  • No --project lynx bench cell beyond the two profiled arms, and no repo-wide
    pnpm format:check, has run against this diff.
  • Oracle clause 1 stays unmet and clause 4 unmeasured. This slice moves
    main-thread script shape inside the program cell; it moves neither oracle.

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

Huxpro and others added 2 commits August 26, 2026 22:04
… for them

The first-screen renderer announces a compiled program's event sites in one
contiguous pass, in site order. The applier then threw that order away: for
every site of every row it searched the whole announcement for the host, and
then that host's list for the type, to recover a position it had just been
handed. #163 C13 priced that search at 38 ms of main-thread script at 30,000
rows, net of the fold hazard its arm controlled for.

So the renderer records where its own announcements begin and how many there
are, and the mount walks that run alongside the sites. The cursor advances only
when an announcement is claimed, which is what leaves a site whose handler came
through undefined open without shifting the sites after it onto the wrong
listeners. The count is carried because only the count says where the run ends:
a skipped site makes it shorter than the site list.

This reads the same source of truth as before — the envelope's own event list,
not a copy of it — so nothing can drift between what the background installs
and what this side binds. It also adds a check the search could never make: an
announcement left inside the run that no site claimed is a listener bound to
nothing, and now a fault rather than silence.

A tree built by hand carries no run and gets the search unchanged, so the
exported applier keeps its contract. A test holds the two readers to the same
answer for the same tree and envelope.

The plan freeze gains the precondition the addressing rests on: `(node, type)`
names at most one site. `prepareUniversalTemplateProgram` already rejects a
program that would violate it, so this is that guarantee restated where the
runtime can see it, for plans that do not come from the compiler. Freezing runs
once per plan, so the check costs nothing per row.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Every test for the run so far hands the applier a tree it built itself, with
the run written by hand, so none of them runs `collectFirstScreenEvents` at
all. That left the renderer's half of the contract unpinned: moving where it
closes the run — after the walk descends into the program's hole rather than
before — makes the run swallow the members' announcements, and nothing went
red.

So this renders one through the real renderer, with members that carry native
events of their own and a program event site the render passes no handler to.
The gap therefore sits inside the run, and the members' announcements sit just
past its end, which is the arrangement a miscounted run gets wrong.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Huxpro and others added 2 commits August 26, 2026 22:21
…teners

Adversarial review of the slice's own diff. The two fields are documented as
both-or-neither, and nothing enforced it: a node carrying `eventsAt` without
`eventsCount` reads as a run of length zero, so every site comes back open and
the program paints with no listeners at all — a page whose taps do nothing,
with nothing red. That is the exact silence this slice exists to remove, so it
cannot be what a half-filled node gets.

The renderer always fills both. This is for the exported applier, whose callers
build their own trees.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
Two 30,000-row bundles in one window, `--control-dist c18`, n=15, AB/BA. The
control arm's digest is `381fe0ab988a479c` — byte-identical to the
`octane-mts-program` bundle every C14–C17 record measured, so the baseline is
the shipping one rather than a re-derivation of it.

`program mount` 246.3 → 196.6, and the whole main-thread script 522.4 → 472.5.
The movement is entirely in the bucket the search lived in; the largest other
move is `applier walk` at +5.7, whose two intervals still overlap, so it is
noise rather than a cost this paid. C13's ablation predicted 38, so the search
was worth slightly more than its arm priced it at.

`c163-c18-run-30000` is the same A/B run earlier against the same control, on
the treatment head before the half-run guard: −48.3 on the same bucket. It is
kept as an independent replication rather than a superseded result. That pair
of files was swept into the previous commit by a `git add -A`, which is why its
message does not mention them.

Every number in the README section was checked against the records: 30 table
claims plus the pilot's four, no mismatches. Three deltas are a tenth away from
what subtracting the rounded columns gives, because each Δ is the difference of
the record's own medians; the section says so.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
…-announcement-run

# Conflicts:
#	packages/lynx/src/main-renderer.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant