Skip to content

perf(lynx): frame-align background commit dispatch - #35

Closed
Huxpro wants to merge 1 commit into
perf/lynx-upstream-attributionfrom
perf/lynx-upstream-pacing
Closed

Huxpro wants to merge 1 commit into
perf/lynx-upstream-attributionfrom
perf/lynx-upstream-pacing

Conversation

@Huxpro

@Huxpro Huxpro commented Aug 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Pace non-empty background commits to the main thread's frame rate by default.
  • Keep the first commit after idle immediate, let renders fold while the gate is closed, and let empty batches cross without spending a frame.
  • Add a 64 ms liveness valve, synchronous fallback for hosts without a frame source, and commitPacing: 'immediate' as an explicit opt-out.

Why

The change-size wire work already makes each update proportional to changed rows, but an update storm can still send one non-empty commit per background tick. That spends main-thread frames on intermediate states. This layer adds backpressure at the Lynx transport boundary while preserving one-shot latency and the existing acknowledgement/effect ordering.

This is the rebased, independently mergeable replacement for the frame-pacing behavior in #10. It does not duplicate upstream octanejs#660/octanejs#661/octanejs#662, and #10 remains historical provenance until the replacement stack is verified.

Changes

  • Add optional pace: true on non-empty commit messages and a root-scoped frame-pulse reply.
  • Resolve the main frame scheduler from an injected test hook, lynx.requestAnimationFrame, or the target's requestAnimationFrame; answer synchronously when none exists.
  • Hold later paced dispatches until the matching pulse, with stale-pulse protection, pre-ACK rejection recovery, and a 64 ms safety timer.
  • Count frame-consuming commits in the build-flag-gated Lynx wire profiler.
  • Add deterministic pacing tests and a paced storm ratio gate.
  • Add a patch changeset for @octanejs/lynx.

Stack

The fork review stack is linked as GitHub Stack octanejs#36 with the official gh stack extension. Upstream delivery remains bottom-to-top because fork-only branches cannot be simultaneous PR bases in octanejs/octane.

Simplification

  • Read the complete perf(lynx): frame-aligned commit pacing for the dual-thread transport #10 commit delta against the live P0 parent and discarded three unrelated generated lockfile/corpus conflicts instead of carrying stale generated state.
  • Reused frozen commit-key tables in protocol validation, removing a fresh key-array allocation from every validated commit.
  • Tightened the benchmark oracle from a theoretical 25-frame ceiling to the number of frames actually pumped during the measured storm; mount/create frames are no longer counted as storm frames.
  • Removed the now-unused public PACED_FRAME_EVERY export and replaced dated/source-branch baseline prose with durable behavioral gates.
  • Kept pacing inside the existing acknowledgement/coalescing state machine; no parallel scheduler or app-level batching abstraction was added.

Performance audit

Exact comparison:

  • parent: fefdc2751ffc9d62d6b292bed038ef8f379683a0
  • candidate: 1d61be7be2286a8de430a780f83975182de89d32
  • host: 32× Intel Xeon Platinum 8336C, Linux 5.15.120.bsk.3-amd64, Node 22.22.2, Chromium 149.0.7827.55
  • raw results: benchmarks/lynx-table/attribution/results/p1-{parent,candidate}-{wire,web}.json (ignored local artifacts; durable values below)

Deterministic wire command, identical source app and Node harness, three drift-checked iterations per SHA:

LYNX_TABLE_SCALES=1000 BENCH_JSON=... node benchmarks/lynx-table/run.mjs 3
node benchmarks/lynx-table/run.mjs 3 # also verified 1k and 10k on each SHA
node benchmarks/bench.mjs --only lynx-table --ratios
operation parent candidate verdict
standard update storm @1k 50 commits / 5,000 commands 50 / 5,000 negative control unchanged
standard update storm @10k 50 / 50,000 50 / 50,000 negative control unchanged
paced update storm @1k unavailable (no pacing) 50 total, 3 frame-consuming / 300 commands / 3 observed frames 94% fewer commands; exactly one non-empty commit per observed frame
select @1k/@10k 2 commands / 225B 2 / 237B command invariant; +12B pace:true, still 88% below the 2KiB budget

All 15 applicable ratio guards passed. Create, update10th, select, and both unpaced storms kept their exact command counts at 1k and 10k.

Lynx-for-Web wall clock, same production build/driver/host window, fresh page per sample, medians of n=5 with min–max spread, zero DNF:

operation parent ms candidate ms delta
create @1k 339.3 [335.0–342.9] 338.5 [332.8–366.0] -0.2%
update10th @1k 58.1 [58.0–68.5] 59.9 [58.1–63.0] +3.1%
select @1k 46.3 [46.1–60.6] 48.2 [46.1–60.6] +4.1%
update storm @1k 246.2 [232.0–248.7] 214.4 [201.7–259.3] -12.9%
select storm @1k 236.6 [58.4–286.1] 143.7 [138.8–177.2] -39.3%
create @10k 2946.5 [2816.3–2977.3] 2799.0 [2789.0–2923.1] -5.0%
update10th @10k 522.3 [509.8–555.4] 542.5 [503.1–550.1] +3.9%
select @10k 397.3 [388.5–405.2] 397.8 [389.6–430.3] +0.1%
update storm @10k 1981.8 [1817.7–2040.6] 1888.8 [1852.6–1957.8] -4.7%
select storm @10k 564.9 [525.6–799.1] 554.1 [487.1–588.7] -1.9%

The deterministic 5,000→300 command reduction is the decision signal. Wall-clock intervals overlap in several cells—especially parent select-storm @1k—so those medians are directional, not stronger causal claims. Every adverse one-shot median is below the 5% repeat threshold.

Production Web bundle: 383.3→385.6 kB raw; gzip 102,690→103,391 B (+0.68%). SHA-256: parent 1ee81ad138a510707349dc9a4451e882bb395af96e2c865f59e9015a6caee6e6, candidate 3e25e1da19a8369524bb793db9bafbfea11d463c915b6a708c8e49086fd7ff69. No cost moved into changed-row commands, one-shot latency, or skipped presentation states; the protocol flag and pacing state account for the small bundle/wire increase.

Validation

  • focused pacing + protocol tests: 29/29
  • full Lynx plus universal transport/native regression: 29 files, 332/332 tests
  • scoped typecheck for the five changed source files and new pacing test
  • pnpm format:files:check for all 12 changed files
  • node benchmarks/bench.mjs --only lynx-table --ratios: 15/15 applicable guards passed
  • pnpm sync
  • git diff --check; final worktree clean

packages/lynx/tests/protocol.test.ts still has its pre-existing standalone typecheck:files errors (Node VM typing plus existing serializable-value/callback fixtures); P1 only changes its scripted frame-pulse behavior, and the file passes Vitest. The changed production files and new test typecheck cleanly.

Risk / follow-ups

  • Universal core still emits empty fold-tail commits. They now cross unpaced and consume no frame, but full empty-commit elision belongs to a later protocol/accounting layer.
  • If a frame source stalls, one held commit may wait up to 64 ms before the safety valve opens. This is a liveness fallback, not a steady-state timer.
  • A host without a usable frame scheduler intentionally behaves like the prior immediate transport.
  • The public root opt-out preserves bisectability and hosts/tests that must observe each commit immediately.

Provenance

@Huxpro

Huxpro commented Aug 11, 2026

Copy link
Copy Markdown
Owner Author

Conclusion: close as failed by current live-main evidence. The reorganized pacing mechanism is not mergeable; its viable successor is the backpressure-driven and zero-command-settlement research in Huxpro/octane issue 45.

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