Skip to content

perf: tear down removed collapsed runs with one destroy-run command - #750

Merged
trueadm merged 8 commits into
octanejs:mainfrom
Huxpro:perf/lynx-clear-teardown-runs
Aug 13, 2026
Merged

trueadm merged 8 commits into
octanejs:mainfrom
Huxpro:perf/lynx-clear-teardown-runs

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Logically stacked on #749 (perf/lynx-bts-render-diet), which logically stacks on #748; submitted from the Huxpro fork against main, so this PR shows the cumulative diff. Merge order = roadmap order.

Summary

  • add a teardownRuns universal driver capability: a removed subtree that is
    still a collapsed program-run instance with implicit contiguous ids skips
    expansion and contributes to one destroy-run command per contiguous range,
    instead of one event/remove/destroy command per host
  • negotiate the capability end to end in the Lynx binding (new teardown-run
    readiness request base), expand the command against the dense record store to
    re-enter the certified teardown fast path (accepted-records fallback for
    reordered/explicit-path rows; general command loop for partial ranges), and
    acknowledge a full-run teardown with a single remove-run delta
  • record one sorted retired-range tombstone per thread instead of 70,000
    generation-map entries per clear cycle; the background client retires compact
    metadata without materializing handles it never observed

Why

Roadmap item 3 of Huxpro#51. Clearing the shared 10k-row table paid four
O(hosts) costs for an O(runs) operation, measured in the item-2 evidence:
3.5 MB / 100k-command teardown stream, 2.9 MB acknowledgement of 70k tombstone
deltas, background expansion of every removed collapsed row (70k logical
records per clear), and 70k generation tombstones per cycle on both threads
(unbounded growth across cycles). #706 kept the command stream as the teardown
certificate; the run command keeps the certificate by construction — the
receiver re-derives the certified sequence from the program it already holds.

Measured effect (shared table app, same host)

  • clear command stream (BTS→MTS): 3,514,556 B / 1 message → ~370 B
  • clear acknowledgement (MTS→BTS): 2,929,786 B / 4 messages → ~813 B
  • create-after-clear stays on the compact acknowledgement from the stacked
    predecessor (~730 B), including across repeated cycles
  • AB/BA vs the stacked predecessor (public runner protocol, n=7 per order,
    both entry orders): clear@10k latency 0.74×/0.81×, btsCpu 0.30×/0.30×,
    mtsCpu 0.82×/0.83×; create@10k latency 0.83×/0.82×, btsCpu 0.21×/0.21×
    (the clear-ACK materialization no longer poisons later creates); select@10k
    0.74×/0.84×; replace@1k 0.91×/0.90×; heap cells 1.00; startup fcp ≤1.0×
    forward and ≈1.0 reverse at every scale. Adverse audit: two sub-frame cells
    read >1.05 in both orders — selectStorm@1k (+3.5 ms on ~33 ms) and
    update10th@1k latency (+1.7/+3.4 ms on ~22 ms) — while their @10k
    counterparts win both orders; same boundary-noise signature as the
    predecessor's settle finding, flagged for the reference-machine rerun.
  • Cumulative vs the re-baselined upstream main on the same container:
    create@10k 1906 → 1148 ms (0.60×) = 0.99× same-container React; clear@10k
    692 → 676 ms while absorbing the predecessor's measurement-boundary debt.

Fallback semantics preserved

  • Rows with refs, explicit node ids, portals, host callbacks, or hidden
    visibility keep the per-host path; drivers that do not advertise the
    capability (the DOM boundary) are byte-for-byte unchanged.
  • Partial-range destroy-run expands into the general command loop; unknown
    ranges are rejected before any mutation; reused id ranges keep bumping
    generations (retired ranges act as generation-one tombstones).
  • Rollback of a segment-retiring acknowledgement restores handles, compact
    metadata, and retired ranges.

Validation

  • emitter-, host-, and client-side regression tests observed red before the
    change (5 tests across three suites)
  • packages/lynx suite: 345 passed; universal suites: 344 passed
  • package-scoped tsc --noEmit clean on octane and clean relative to
    base on @octanejs/lynx (one pre-existing unrelated error)
  • pnpm format:files:check on changed files; pnpm sync clean
  • end-to-end wire verification on the shared table app across 3
    create/clear cycles
  • AB/BA full-suite runs both orders, zero DNF (archived in the benchmark
    repo with vendored Lab entries at this commit)

Risk / follow-ups

  • The full-run fast path synthesizes the certified command list on the main
    thread (O(hosts) object churn without wire/parse costs); moving the certified
    validation to consume the run directly is a follow-up if MTS profiles show it.
  • Startup adoption still pays its reverse publication (roadmap item 4).

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


Generated by Claude Code


Note

Medium Risk
Touches cross-thread commit/ack bookkeeping and host id lifecycle (retired ranges, generation checks); fallbacks preserve prior behavior but Lynx teardown correctness is security- and stability-sensitive at scale.

Overview
Clears of large keyed tables no longer expand every removed collapsed row into per-host remove/destroy/event commands. The universal renderer gains a teardownRuns capability and a destroy-run host command; eligible removed program-run subtrees (implicit contiguous ids, no refs/portals/callbacks) are coalesced into one command per contiguous range instead of expanding to per-host teardown.

The Lynx stack negotiates teardownRuns (new readiness request base), expands destroy-run on the main thread against the dense record store (certified fast path for full runs; records fallback for reordered/explicit rows; general loop for partial ranges), and answers full-run teardown with a single remove-run acknowledgement delta. Both threads replace per-host generation tombstones with sorted retired [first, last] ranges; the background client retires compact metadata without materializing handles it never saw.

Drivers without the capability (e.g. DOM) and rows that need per-host observability keep the previous explicit path. Regression tests cover partial teardown, post-fault clears, rollback, and id reuse/generation bumps.

Reviewed by Cursor Bugbot for commit d00a52c. Bugbot is set up for automated code reviews on this repo. Configure here.

Huxpro added 3 commits August 12, 2026 19:42
…ation

Add a speed-of-light probe that materializes the exact 10,000-row table
shape with a bare public Element PAPI loop in the same main-thread realm
as the Lynx receiver, interleaved AB/BA with octane control/profile
create cells, and record the measured floor:

- papi_element_creation is 99.0% platform floor (collapsible 0.5% of
  the create wall)
- mt_apply_other is 84.7% floor-equivalent (collapsible 4.6%)
- chunked vs single flush makes no difference

All three sub-owner candidates from the roadmap fail the >=10% owner
gate for per-element MTS machinery on the web harness.
A compact first mount could only engage once per root: the main thread
kept implicitInitialGenerations set forever and the background client
refused further compact acknowledgements while retired segment metadata
existed, so every create after a clear republished a full per-host
handle delta - 17.4 MB of reverse traffic, ~600 ms of main-thread wall,
and eager background materialization of all 70k handle entries on the
shared 10k-row table. The public benchmark's warmed-page protocol
measures exactly this path.

- reset implicit generation bookkeeping when a certified dense teardown
  leaves every surviving record's generation stored
- gate compact eligibility on a fresh-id ratchet (maxExplicitId) so
  implicit generation-one segments can never cover a reused id and
  remounts keep bumping generations on the explicit path
- retire background compact metadata when its last live host code is
  removed, restoring it on rollback

Create-after-clear acknowledgement: 17,330,831 B -> 719 B; warmed-page
create@10k wall median 2,028 -> 1,511 ms on the same host with fresh
cells unchanged. Adds bts-profile.mjs (background/page attribution with
wire deltas, fresh vs warmed-protocol cells) and its measured results.
Clearing a 10k-row keyed table shipped a 100,000-command teardown stream
(3.5 MB), acknowledged it with 70,000 tombstone deltas (2.9 MB), expanded
every removed collapsed row into seven logical records just to enumerate
those commands, and grew both threads' generation tables by 70,000
entries per cycle.

The universal renderer now advertises a teardownRuns driver capability:
a removed subtree that is still a collapsed program-run instance with
implicit contiguous ids skips expansion and contributes to one
destroy-run command per contiguous range. The Lynx binding negotiates
the capability, re-enters the certified teardown fast path by expanding
the command against its dense record store (with an accepted-records
fallback and a general-loop path for partial ranges), acknowledges a
full-run teardown with a single remove-run delta, and records one
sorted retired-range tombstone per side instead of 70,000 map entries.

Clear command stream 3,514,556 B -> ~370 B; clear acknowledgement
2,929,786 B -> ~813 B; compact create acknowledgements survive the
cycle. Reused ranges keep bumping generations; emitter-, host-, and
client-side regression tests were observed red before the change.
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Aug 13, 2026
Comment thread packages/lynx/src/core/host-driver.ts Resolved
Comment thread packages/lynx/src/core/client-driver.ts Resolved
leonidaz and others added 4 commits August 13, 2026 15:13
# Conflicts:
#	benchmarks/lynx-table/stages/papi-floor.mjs
#	benchmarks/lynx-table/stages/results/bts-profile-10000.json
#	benchmarks/lynx-table/stages/results/papi-floor-10000.json
#	benchmarks/lynx-table/stages/results/papi-floor-10000.md
#	packages/lynx/src/core/client-driver.ts
#	packages/lynx/src/core/host-driver.ts
#	packages/lynx/tests/host-driver.test.ts
#	packages/lynx/tests/protocol.test.ts
…rdown-runs

# Conflicts:
#	packages/lynx/tests/host-driver.test.ts
#	packages/lynx/tests/protocol.test.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but it could not run because the branch was deleted or merged before autofix could start.

Reviewed by Cursor Bugbot for commit e611944. Configure here.

Comment thread packages/lynx/src/core/client-driver.ts Resolved
@trueadm
trueadm marked this pull request as ready for review August 13, 2026 19:42
@trueadm
trueadm merged commit 94fa199 into octanejs:main Aug 13, 2026
45 checks passed
trueadm added a commit that referenced this pull request Oct 3, 2026
… to renderers that use them (#1652)

* perf(octane): ship universal host bindings and template programs only to renderers that use them

Weekly Bench's three-bundle-size guards breached at 1.059x (minimal) and
1.042x (full catalogue) of React Three Fiber. Since #677, octane-min grew
15.6 KB gzip, almost all of it in universal-core.ts (131 KB -> 178 KB
minified). The largest additions were Lynx-only template paths (#693, #700,
#716, #750) and opt-in host bindings (#1044). @octanejs/three itself was flat.

- universalHostBinding() now installs the subscription, flush, and
  binding-only transaction code on its first call. The root keeps one lazy
  binding state instead of seven eager fields, and commits skip the
  per-host binding loops when no binding can exist.
- Template programs are a driver opt-in: templateProgramMount,
  templateProgramRuns, and collapsedTemplateMount take effect only with
  `templates: universalHostTemplates`. The Lynx background driver passes it.
  Program preparation, collapsed-template materialization and expansion, and
  the compact template update now sit behind that object.

octane-min 199019 -> 193811 gzip (1.031x), octane-full 260746 -> 255569
(1.021x). The guards ratchet to 1.034 and 1.024; reaching 1.0 needs a
broader universal-core diet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* chore: split the Lynx changeset from the octane changeset

The changeset check rejects a changeset that mixes the ignored private
@octanejs/lynx package with octane.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants