Skip to content

perf(lynx): drop the teardown record mirror - #248

Merged
Huxpro merged 1 commit into
new-lynxfrom
perf/lynx-teardown-mirror-verdict
Aug 30, 2026
Merged

Huxpro merged 1 commit into
new-lynxfrom
perf/lynx-teardown-mirror-verdict

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 30, 2026 •

Copy link
Copy Markdown
Owner

Summary

The teardown-mirror verdict from #230 Order 3, landed. Stacked on #245
(perf/lynx-clear-skips-redundant-unbinds) — target that branch, review #243 →
#245 → this.

A mount-template-run whose incremental compact declined copied every accepted
record into a second LynxDenseHostRecordStore and retained it until the next
batch, so a later destroy-run could be expanded from the run's shape rather
than from the record map. The copy is gone.

Why

Three independent measurements say the mirror never earned its retention:

evidence source number
what the mirror costs #230 Order 3 +31.64 MB retained peak
what the mirror releases #230 Order 3 −2.12 MB
what the mirror saves at clear time issue57-clear-teardown.json destroyRunExpandMs 13.71 ms of 372 ms

And two changes removed its remaining justification:

A cache that costs 15× what it releases, to save 3.7% of the operation it
accelerates, on a path that now produces byte-identical output either way, is
not a cache. It is retention.

There is also a second-order gain: prepareDirectFullTeardown's refusal list
loses the state.teardownRecords !== null condition, so the certified direct
plan is reachable in one more case
than before — a case where a live mirror
previously blocked the very path that is cheapest.

Changes

packages/lynx/src/core/host-driver.ts — 14 sites, net −50 lines:

  • the copy itself: the ~27-line block that built new Map(state.records) and
    seeded a fresh dense store from it;
  • LynxHostState.teardownRecords and its four assignment sites (adopt, commit,
    reset, dispose);
  • teardownDense on the mount-template operation type, its
    conditional spread into operations.push, and the
    operation.teardownDense?.setNode(...) write in the node-binding loop;
  • teardownMirrorCandidate and acceptedTeardownRecords;
  • state.teardownRecords !== null || from prepareDirectFullTeardown's
    refusal list;
  • the dispatch site now reads
    state.records instanceof LynxDenseHostRecordStore ? state.records : null.

packages/lynx/tests/host-driver.test.ts — the test #243 added had silently
gone vacuous.
With the mirror deleted, both of its arms took the record-map
route, and the whole suite passed 730/730 while the differential proved nothing.
Caught by asking why a deletion cost zero tests, not by a failure.

Rewritten as a dense-store vs record-map differential:

  • the program is the real bench row shape — view (class binding) → text →
    #text (value binding) — so dynamicRoutes yields a dense-eligible program;
  • arm A paints clean and the incremental compact accepts, so the store is a
    LynxDenseHostRecordStore and the run tears down through it;
  • arm B parks a neighbour host id above the run's id space, the compact
    declines, and the same teardown resolves through the record map;
  • probe-verified that the arms actually diverge: [[false, []], [true, ["records-map"]]].

The two routes legitimately publish differently — dense emits one
destroy-run delta, the map emits nine destroys — so asserting raw delta
equality is wrong. The test normalizes both to the sorted set of retired
id:generation identities (9 handles either way) and asserts the host-call
sequences are equal
, which is the property that actually matters.

Validation

  • pnpm format:check — via pnpm format:files on all changed files, clean

  • pnpm typecheck — see the multiset note below

  • pnpm test — not re-run for this commit; see below

  • targeted tests:

  • npx vitest run --project lynx — 48 files, 730 passed.

  • Red-verified. Broke the record-map route so it drops row 0's remove; the
    test failed with the expected mismatch; restored. A test nobody has watched
    fail is not protecting anything — and this one had already proved that once.

  • pnpm typecheck:files on both changed files reports 40 errors in
    host-driver.test.ts. All 40 are pre-existing: stashed the diff, re-ran,
    got 40; diff of the two sorted error multisets is empty. No new errors.

  • pnpm sync — clean (regenerated AGENTS.md, context budget check passed).

  • pnpm test (repo-wide) was run on the parent commit (perf(lynx): stop describing unbinds a teardown's own destroy subsumes #245) and produced 3
    failures, all three proven pre-existing there by reverting src to base
    8938c1260 and reproducing each in isolation. This commit touches the same
    two files plus a changeset, so that finding carries; the lynx project suite is
    the meaningful gate and it is green.

Risk / follow-ups

Provenance

  • An agent produced this diff (agent-authored)

Generated by Claude Code

A `mount-template-run` whose incremental compact declined copied every
accepted record into a second `LynxDenseHostRecordStore` and kept it live
until the next batch, so a later `destroy-run` could be expanded from the
run's shape instead of from the record map.

Order 3 priced that copy: +31.64 MB retained peak to release 2.12 MB, and
`destroyRunExpandMs` is 13.71 ms of a 372 ms clear. #243 established that
both routes describe the same teardown, and #245 made both cost one host
call per row. The mirror never earned its retention.

Removing it also shortens `prepareDirectFullTeardown`'s refusal list by
one condition, so the certified direct plan is reachable in a case where a
live mirror previously blocked it.

The differential test #243 added silently became vacuous once the mirror
was gone — both arms took the record-map route — so it is rewritten as a
dense-store-vs-record-map differential. The two routes publish handle
deltas in different shapes (one `destroy-run` vs nine `destroy`s), so it
normalizes both to the set of retired `id:generation` identities and
asserts the host-call sequences match exactly.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019RsC3U39kUuLKajZANeTVy
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