Skip to content

perf: reduce effect and ref postorder ancestry scans - #998

Merged
domgan-oai merged 2 commits into
octanejs:mainfrom
openai-oss-forks:codex/perf-effect-postorder
Sep 8, 2026
Merged

domgan-oai merged 2 commits into
octanejs:mainfrom
openai-oss-forks:codex/perf-effect-postorder

Conversation

@domgan-oai

@domgan-oai domgan-oai commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Why

The previous comparator scans both complete parent chains for each comparison, even when comparing a component with its direct parent or a sibling.

Changes

  • Check direct parents and shared parents before scanning the remaining chains; preserve enqueue order for disjoint components and registration order within one component.
  • Add a nested shallow-sibling/deep-branch lifecycle test for mount, cleanup, and update in development and production suites.
  • Add a benchmark that checks pairwise order against upstream main and measures chain, sibling, and uneven-branch sort workloads. Add an octane patch changeset.

Validation

  • Red CI run: the new test failed in both development and production on a deliberately broken comparator, including the child-before-parent assertion.
  • Focused benchmark: 400-level chain parent reads 80,199 → 798 and median comparator sort 179.99 → 5.92 µs; 1,000 siblings 3,996 → 1,998 reads, 17.46 → 14.88 µs; uneven 525-node tree 12,989 → 11,623 reads, 51.91 → 50.17 µs. These figures measure sorting alone, not full renders.
  • node scripts/workspace-packages.mjs --check, git diff --check, and focused benchmark ordering gates.
  • Current-head CI passed with the repaired comparator: every runtime, React parity, lint, typecheck, integration, and package validation job succeeded.
  • Local pnpm sync, Vitest, and typecheck: the configured Socket registry returned HTTP 403 for pinned @tsrx/[email protected] before scripts could start; frozen-lockfile supply-chain verification passed. The offline filtered install also lacked @tsrx/[email protected].

Risk / follow-ups

  • Browser lifecycle timing remains unmeasured locally due to the registry failure; CI exercises the full runtime, and the benchmark isolates comparator cost.

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
Changes commit-phase ordering logic for effects and refs; incorrect comparisons would be user-visible, though existing and new conformance tests target the tricky cross-depth and nested lifecycle cases.

Overview
Optimizes how queued layout/passive effects and ref attachments are sorted so commit order still matches React’s post-order tree walk, with fewer parentBlock walks during sorting.

comparePostOrder in runtime.ts no longer calls blockIsAncestorOf twice per comparison. It resolves direct parent/child pairs, same-parent siblings (via enqueue seq), then only walks one side’s chain when needed before falling back to aSeq - bSeq.

Adds a standalone benchmark (benchmarks/effect-postorder) that extracts the comparator from a Git ref vs the worktree, checks postorder correctness, counts parent reads, and reports median sort time for chain, sibling, and mixed trees.

Adds conformance coverage (NestedLifecycleOrder) for shallow sibling + deep nested tree layout and passive effect order across mount and update, including cleanups.

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

@domgan-oai
domgan-oai marked this pull request as ready for review September 8, 2026 17:49
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent perf PR: performance work labels Sep 8, 2026
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.

1 participant