Skip to content

perf(lynx): drain reentrant commits linearly - #860

Merged
trueadm merged 1 commit into
mainfrom
fix/linear-lynx-commit-drain
Aug 26, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/linear-lynx-commit-drain

Conversation

@jonkwheeler

@jonkwheeler jonkwheeler commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • drain synchronous reentrant Lynx commits with a cursor instead of repeated front shifts
  • add a real-path 10k/20k scaling benchmark and ratio guard

Why

  • front-shifting the queue copied its remaining tail on every commit, making large reentrant bursts quadratic
  • matched five-sample runs reduced 20k from 249.2 ms to 113.9 ms (54.3%) and scaling from 4.43x to 2.02x

Changes

  • tombstone consumed queue slots so processed messages remain collectible without tail copies
  • verify every acknowledgement/completion and the final native value in lynx-render
  • guard 20k/10k reentrant-drain scaling at 3.5x

Validation

  • pnpm format:check
  • pnpm typecheck
  • pnpm test
  • targeted formatting: changed files pass pnpm format:files:check
  • targeted tests: pnpm --filter @octanejs/lynx test (25 files, 362 tests)
  • targeted typecheck: tsgo --noEmit for Lynx source, testing, and typetests projects
  • benchmark: node benchmarks/bench.mjs --quick --ratios lynx-render
  • pnpm sync

Risk / follow-ups

  • The committed scaling guard allows normal timing variance while rejecting the former superlinear drain.
  • The package-local tsc script still reports the pre-existing acknowledgement literal error at src/main-thread.ts:2257; root/CI uses tsgo, and all three relevant tsgo projects pass.

Provenance

  • An agent produced this diff (agent-authored)

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Touches Lynx main-thread commit ordering and reentrant queue draining on the hot transport path; behavior is guarded by targeted tests and new benchmark correctness checks.

Overview
Fixes superlinear drain cost when many Lynx commits are queued synchronously during Element PAPI work (e.g. reentrant __SetID). The main-thread commit loop no longer shift()s the pending queue; it walks with an index, tombstones consumed entries, then clears the array so large bursts stay O(n) instead of copying the tail on every dequeue.

Adds an Octane-only lynx-render workload (runReentrantCommits) that fires a 10k/20k commit burst from inside one host update, checks ordered acks/completions and the final native id/version, and records drain_ms. ratios.json caps 20k vs same-run 10k at 3.5x to catch regressions back toward the old ~4.4x scaling.

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

@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Aug 26, 2026
@jonkwheeler
jonkwheeler marked this pull request as ready for review August 26, 2026 13:47
@jonkwheeler
jonkwheeler requested a review from trueadm August 26, 2026 14:23
@trueadm
trueadm merged commit 7b45274 into main Aug 26, 2026
50 checks passed
@trueadm
trueadm deleted the fix/linear-lynx-commit-drain branch August 26, 2026 15:04
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.

2 participants