Skip to content

perf(lynx): validation diet — dev-deep, prod-fast commit validation ([lynx-perf 5]) - #13

Closed
Huxpro wants to merge 1 commit into
lynx/plan-wirefrom
lynx/validation-diet
Closed

Huxpro wants to merge 1 commit into
lynx/plan-wirefrom
lynx/validation-diet

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Closes #6. Stacked on #12 ([lynx-perf 4], base lynx/plan-wire), which stacks on #11 → #10 → #1.

Summary

  • Production builds now compile the deep validation walks out of the Lynx commit pipeline while keeping envelope validation and every load-bearing check unconditional. Main-thread prepare drops 3.8× on the 10k-row rig (whole-run 11,239ms → 2,947ms), inbound validate drops ~90× (331ms → 3.7ms), and the acknowledgement path ~1.2× — with every deterministic counter byte-identical.
  • The dev/prod split rides the existing LYNX_DEVELOPMENT define (process.env.NODE_ENV !== 'production', folded by Rspeedy/Rspack/Vite): development, vitest, and the two-realm CI rig keep every check exactly as before; an unsubstituted native bundle reads as production, which is what it is.
  • Fail-stop is preserved, not weakened: a corrupt commit in production still rejects loudly through the unconditional staging guards (duplicate ids, record existence, attach-state transitions, cloneProps ownership) and the apply-time fault path. A new dual-thread suite runs the real pipeline with production modules — the configuration no other suite exercised — and pins both halves: real scenes behave identically, and corruption faults instead of applying.

Why

  • Issue [lynx-perf 5] Validation diet: full structural checks in dev, envelope-only in production #6: per-command validation was measured at 10–15% of prepare, and the whale was the final whole-tree check pass — O(final tree ≈ 70k hosts) per commit at 10k rows, re-walking every accepted host on every commit to re-prove invariants that only new state can break. On a correct build those checks only ever answer "valid"; development is where incorrect builds live.
  • Constraint from the issue kept: cloneProps (deep clone + freeze + cross-realm plain-prototype enforcement + worklet unwrap) is behavior — ownership and defense — and stays unconditional, as do all record-existence and attach-state checks the staging logic relies on.

Changes

  • packages/lynx/src/core/protocol.ts: assertBatch keeps the envelope (exact keys, renderer/version match, commands array) and gates the per-command structural walk; the ack branch gates the per-delta walk (the background's handle-delta reconciliation independently verifies every delta against staged transitions); assertFirstTreeSnapshot keeps the envelope and gates the per-node walk (adoption touches every node anyway and faults on a shape it cannot adopt).
  • packages/lynx/src/core/host-driver.ts: the pure assert helpers (assertSafeId, assertHostType, assertTextProps, assertNoCycle, assertNoMainThreadEventCollision) no-op in production at their definitions, so the development flow stays byte-identical; compound inline checks (text-parent, list-item placement, event-prop shape, destroy connectivity) gate in place; the whole-tree finalIds set is built only in development or for first-tree adoption, so production prepare is O(batch), not O(final tree); the final check pass is development-only, with production collecting live lists from accepted + staged records (same membership, argued in-code).
  • packages/lynx/src/core/profiling.ts: LynxWireProfile gains prepareCheckMs — the development-only check share of prepareMs, accumulated inside the driver, so prepareMs − prepareCheckMs is the staging cost both builds share. Production reports 0 there by construction.
  • packages/lynx/tests/validation-diet.test.ts (new, 5): a production-module dual-thread rig (NODE_ENV=production + fresh module registry, real jsdom Element PAPI). Scenes: full render/update/replace/unmount lifecycle; native-list creation + membership update; a minimally corrupt commit (fresh id, real type, null props — cloneProps is the only guard left) rejecting loudly; a duplicate host id rejecting; a malformed commit envelope rejecting. All five assert the DOM never changes on a rejected commit.
  • Changeset: @octanejs/lynx patch.

Measured

Same instrument as every cell in this stack: the deterministic in-process dual-thread rig (benchmarks/lynx-table, __OCTANE_LYNX_PROFILE__ build, NODE_ENV=production), whole-run at 10k rows, 3 reps back-to-back on a quiet host, medians:

whole-run @10k before (#12 head) after change
prepareMs 11,239 2,947 3.8×
validateMs 331 3.7 ~90×
ackMs 4,606 3,829 1.2×
applyMs 1,213 1,098 unchanged (noise)
commits / paced / commands 174 / 87 / 304,416 174 / 87 / 304,416 byte-identical

node benchmarks/bench.mjs --only lynx-table --ratios → PASS, 25 guards checked, all deterministic counters unchanged (this diff removes checks, never commands). No ratio-guard changes: milliseconds are host-bound and deliberately not gated.

Acceptance vs issue #6:

  • prepare @10k ≥3× faster in the production build: met — 3.8× whole-run on the rig instrument (the run is create-and-storm dominated; the issue's original 266ms/62ms figures predate feat(lynx): change-size-proportional commit wire cost, with a gated cross-framework benchmark (integration of 3 upstream PRs) #1/[lynx-perf 4] Plan-aware wire: instantiate-by-plan-id instead of per-node create commands #5's command-volume reductions, so the ratio is the comparable claim).
  • FCP@10k ≥100ms better: not met — unchanged within noise. Lynx-for-Web probe (BENCH_AUTOROWS=10000 build, Chromium, 3 reps each, medians): first text 5,614ms → 5,546ms, full 10k rows 5,910ms → 5,848ms, with rep spreads (±250ms) larger than the deltas. The reason is structural: the rig's first screen is main-thread-rendered, so commit-prepare validation was never on the FCP critical path — the walks this diff removes run post-FCP (background commits, acknowledgement, adoption). The issue's FCP prediction assumed validation sat before first paint; on this rig it does not. Reference frameworks not measured (no autorows reference bundles exist).
  • dev suites green with validation on: met — the full lynx directory (27 files / 300 tests, includes the two-realm rig) passes.
  • prod smoke "fault, not UB": met — the new suite above.

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test — full root run on this head: 16,917 passed / 106 skipped. 19 failed files = exactly the pre-existing environmental set from the PR perf(lynx): plan-aware wire — fold provable plan instances into instantiate-by-plan-id commands ([lynx-perf 4]) #12 baseline (Playwright-browser suites without a Chromium download, macOS-only rspeedy native-demo, website ssr suites); zero new failures.
  • targeted on the final diff: packages/lynx/tests (27 files / 300 tests, two-realm rig with validation on, incl. the 5 new production-module scenes)
  • node benchmarks/bench.mjs --only lynx-table --ratios → PASS (25 guards)
  • red-checked against realistic broken diets, each restored after going red: gating the duplicate-id check (duplicate test fails), gating the cloneProps ownership check (corrupt-commit test fails: the commit applies silently), gating the list collection (membership test fails: the new item never becomes enterable), over-gating placement staging (lifecycle + list tests fail). Reverting the diet entirely (all checks back on everywhere) keeps every test green by design — the suite pins behavior equivalence and fail-stop, both of which a checks-everywhere build satisfies; the performance claim is carried by the measured table, not a unit test.

Risk / follow-ups

  • The corruption surface in production is commands from the same application's background bundle; the failure mode of the removed walks is later, coarser diagnostics for a corrupt build (a staging-guard reject instead of a labeled protocol error), never silent application — pinned by the new suite.
  • The production list collection (accepted ∪ staged live lists) is deliberately redundant with the creation-time item snapshot; it preserves listUpdates membership identical to development at O(batch) cost.
  • FCP remains the province of [lynx-perf 7] Receiver diet: shrink the MT slice, spend it on FCP #8 (receiver diet / MT slice): this diff proved validation is not on the first-screen critical path of this rig.
  • prepareCheckMs lets a dev-profile build split check vs staging share; production builds report 0 by construction.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code

https://claude.ai/code/session_013br9KPN1riTSP683xEvUuU


Generated by Claude Code

Envelope validation and load-bearing checks (duplicate ids, record
existence, attach-state transitions, cloneProps ownership) stay
unconditional; the per-command, per-handle-delta, and per-snapshot-node
structural walks plus the whole-tree prepare check pass become
development-only. Production keeps fail-stop: a corrupt commit rejects
loudly through the staging guards and the apply-time fault path, pinned
by a new production-module dual-thread suite. The profile hook gains
prepareCheckMs, the dev-only check share of prepareMs.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013br9KPN1riTSP683xEvUuU
@Huxpro

Huxpro commented Aug 11, 2026

Copy link
Copy Markdown
Owner Author

Conclusion: close as not currently justified. The old validation-diet driver no longer owns a material share of current main; PR 700 profiles capability validation at only a small first-screen cost.

@Huxpro Huxpro closed this Aug 11, 2026
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