Repository navigation
perf(lynx): read a program's listeners from the run, not by searching for them - #214
Merged
Merged
Conversation
… 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
…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
This was referenced Aug 26, 2026
Huxpro
marked this pull request as ready for review
August 27, 2026 18:41
…-announcement-run # Conflicts: # packages/lynx/src/main-renderer.ts
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue #163, slice C18 — the first reduction in
off_boundary'spublishbucket 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 (.findwith afresh 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 mount208.9 → 167.0 for the positional arm). Measured against thishead 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.eventsitself, not a copy), so nothingcan drift between what the background installs and what this side binds.
It also adds two faults where there was silence:
background installed and this side bound to nothing; and
eventsAtwithouteventsCount, which reads as an empty runand 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.
freezePlanNodegains the precondition the addressing rests on —(node, type)names at most one site.
prepareUniversalTemplateProgramalready rejects aprogram 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.tsfreezePlanNoderefuses a program plan binding two events of one type toone node.
FirstScreenProgramcarrieseventsAt/eventsCount;collectFirstScreenEventsfills them around its own announcing loop, before the walk descends.
packages/lynx/src/core/host-driver.tsLynxFirstScreenDirectNodecarries the same two fields, both optional.mountProgramwalks the run with a cursor and verifies each claim, fallingback 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/stages/results/, and the README section that readsthem.
Validation
pnpm format:checkpnpm typecheck— scoped:pnpm typecheck:filesover the four changedfiles. Clean for the two
src/files andfirst-screen-direct.test.ts.main-renderer.test.tsreports twoTS2554errors 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 invitest.config.jsincludingoctane-prod, exit code 0.lynxproject, 43 files / 639 tests, green.pnpm format:filesover the four changed files — all unchanged.pnpm sync— clean.Every new test was watched failing. Six deliberate breakages of the
implementation, each caught:
leaves a site nothing was announced for open…,installs what the search installs…faults when the run carries an announcement no site claimedreads the program's own listeners and leaves its hole's members alonerefuses a node carrying half a run rather than painting it without listenersrefuses a compiled program whose tables name nodes it does not makeThe 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
collectFirstScreenEventsat all. The second commit is the end-to-end testthat 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.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 thelargest 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 mount242.4 → 194.1 (−48.3), allframes 509.5 → 467.2.
stages/results/c163-c18-run-30000.jsonis kept forthat reason rather than discarded as superseded.
The control arm's digest is
381fe0ab988a479c— byte-identical to theoctane-mts-programbundle every C14–C17 record measured. Bundles: control520,098 B, treatment 520,964 B /
9edb29cf145c659a.These milliseconds are the profiler's, not the wall clock's. No FCP or
papi-run.mjswall measurement has been taken against this diff.envelope.eventsis unchanged — same entries, same order, same bytes — and therun is two integers on a main-thread-local node, so oracle clause 2 is
untouched by construction rather than by measurement.
Risk / follow-ups
eventsByHostis still built over the whole envelope, and after this change aprogram'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.
--project lynxbench cell beyond the two profiled arms, and no repo-widepnpm format:check, has run against this diff.main-thread script shape inside the program cell; it moves neither oracle.
Provenance
agent-authored)Generated by Claude Code