Skip to content

perf: re-arm compact acknowledgements after certified teardown - #749

Merged
leonidaz merged 3 commits into
octanejs:mainfrom
Huxpro:perf/lynx-bts-render-diet
Aug 13, 2026
Merged

leonidaz merged 3 commits into
octanejs:mainfrom
Huxpro:perf/lynx-bts-render-diet

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Logically stacked on #748 (perf/lynx-papi-floor); submitted from the Huxpro fork against main, so this PR shows the cumulative diff. Merge order = roadmap order.

Summary

  • re-arm compact acknowledgements after a certified teardown retires a dense run,
    so a create after a clear publishes a few hundred bytes instead of a full
    per-host handle delta (17,330,831 B → 719 B on the shared 10k-row table)
  • 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; retire background compact metadata when its last
    live host code is removed (restored on rollback)
  • add benchmarks/lynx-table/stages/bts-profile.mjs: background/page-realm
    attribution with per-op wire deltas, fresh-page vs featured-warmed-protocol
    cells, plus its measured results

Why

Roadmap item 2 of Huxpro#51. Owner-first measurement (bts-profile, n=5,
AB interleaved) showed the featured benchmark's warmed-page protocol pays a
re-publication cliff octane's fresh-page numbers never see: every create after
a clear shipped 17.2–17.4 MB of dispatchCoreContextOnBackground traffic
(70k × {op:'create', handle} deltas), eagerly materialized 70k background
handle entries, and added ~600 ms of main-thread wall. Mechanism: compact
acknowledgements could only engage once per root — implicitInitialGenerations
ratcheted on forever, and the background client refused further compact ACKs
while retired segment metadata existed — so the steady state the public
ranking measures ran permanently on the worst path.

Measured effect (same host, public runner protocol, AB and BA orders, n=7)

cell baseline fwd/rev fix fwd/rev ratio fwd/rev
create@1k latency 172.0 / 163.4 113.0 / 110.6 0.66 / 0.68
create@1k btsCpu 62.2 / 61.9 18.4 / 20.2 0.30 / 0.33
create@10k latency 1905.7 / 1919.3 1450.4 / 1449.9 0.76 / 0.76
create@10k mtsCpu 1585.9 / 1671.1 1106.3 / 1077.5 0.70 / 0.64
create@10k btsCpu 869.0 / 891.3 640.2 / 727.5 0.74 / 0.82
clear@10k latency 691.5 / 733.3 951.4 / 968.8 1.38 / 1.32 †
heapMts / heapBts — — 1.000 / 1.000

† The clear cell is a measurement-boundary transfer, not a product regression:
the public runner clicks the timed clear immediately after its setup create
without settling, and with the fix the create predicate fires before the
browser's one-shot layout pass instead of after it (the 17 MB acknowledgement
serialization used to keep the main thread busy past layout). Draining the
setup debt with one settle makes the cells identical — baseline 701.1 ± 60.6 ms
vs fix 694.1 ± 19.9 ms (n=7, same window) — and the create+clear cycle
total improves ~8% in both orders either way. The same effect accounts for the
small swap/remove ratio shifts (±1–4 ms absolute on ~20 ms cells). Storms,
select, update10th latency, and both heap cells are unchanged; wire
create-bytes/row crown is unchanged (fresh create still publishes ~1 KB).

A dedicated n=15 startup probe (stock runner, one window) resolves the n=5
startup readings as noise: fcp deltas are +0.7% / +0.6% / +1.2% / +2.1% at
0/1k/10k/30k rows — all under the 5% adverse gate; the startup path takes none
of the changed branches (no teardown, no compact metadata at boot).

Invariants preserved

  • Reused id ranges (remounts over retired ids) still take the explicit path and
    keep bumping generations — pinned by the new host-driver regression test and
    the existing retires a complete compact run… test.
  • A rolled-back segment-retiring acknowledgement restores the compact metadata
    and keeps refusing new compact ACKs — pinned by the new client-side test.
  • Stale-generation rejection, handle identity, first-screen adoption: full
    packages/lynx suite green (344 tests).

Validation

  • both new regression tests observed failing before the fix
  • npx vitest run packages/lynx/tests/ — 344 passed
  • package-scoped tsc --noEmit clean relative to base (one pre-existing
    unrelated error in main-thread.ts exists on base and head alike)
  • pnpm format:files:check on changed files; pnpm sync clean
  • end-to-end wire verification on the shared table app: create-after-clear
    acknowledgement 17,330,831 B → 719 B, rendered output identical
  • pnpm test (full repo): 20,673 passed / 54 failed / 194 skipped — every
    failure is in browser-integration projects that need the pinned Playwright
    browsers, GPU, or unproxied networking this container lacks (three, pdf,
    doom, draggable, plugin browser suites); zero failures under packages/lynx
    or packages/octane

Risk / follow-ups

  • Background clear-ACK processing still materializes retired compact entries
    eagerly and the clear command stream remains O(n) — roadmap item 3.
  • Follow-up for the harness (separate repo): ensurePre('rows') does not settle
    before the timed sample, so setup rendering debt can land in whichever cell
    runs next; a one-line settle equalizes it for every entry.
  • Bundle cost: +996 B raw per web bundle (+0.2%).

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


Generated by Claude Code


Note

Medium Risk
Touches host/client generation and compact-ack bookkeeping on a hot create-after-clear path; behavior is heavily regression-tested but incorrect ratchet or teardown logic could break handle identity or stale-generation rejection.

Overview
Restores incremental compact handle acknowledgements after create/clear cycles so steady-state table creates no longer ship a full per-host delta (~17 MB → ~719 B on the 10k-row app).

On the host driver, certified dense teardown can clear implicitInitialGenerations when every surviving record has an explicit generation; incremental compact runs must use firstId > maxExplicitId so reused id ranges stay on the explicit path with generation bumps; maxExplicitId is maintained on accept/teardown/compact.

On the background client, compact segment metadata tracks a live host count, drops the segment when the last compact code retires (with rollback restore), and no longer blocks a later compact ACK via the “fresh container” guard.

Adds bts-profile.mjs (CDP profiling of the Lynx background worker, fresh vs warmed harness protocol) plus sample 10k-row results, and regression tests for re-arm after teardown and client-side metadata retirement.

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

Huxpro added 2 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.
@trueadm
trueadm marked this pull request as ready for review August 13, 2026 14:48
@leonidaz
leonidaz merged commit 3efd622 into octanejs:main Aug 13, 2026
65 of 70 checks passed
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