Skip to content

perf(dom-fence): limit observer maintenance to affected roots - #341

Merged
taekchef merged 1 commit into
omdsh-dev:mainfrom
sunxiuguo:perf/dom-fence-dirty-maintenance-321
Oct 21, 2026
Merged

taekchef merged 1 commit into
omdsh-dev:mainfrom
sunxiuguo:perf/dom-fence-dirty-maintenance-321

Conversation

@sunxiuguo

Copy link
Copy Markdown
Contributor

Scope

Refs #321, specifically the first remaining optimization in the maintainer's comment: incremental maintenance of existing DOM-fence mounts and diagnostics. This does not close the whole streaming-performance report.

The narrow scope was confirmed in #321 (comment).

Changes

  • Track affected mounts and diagnostics separately from the existing discovery queue.
  • Resolve container wipes through a reverse WeakMap, rather than searching every root.
  • Select affected ancestors, changed subtrees, and structural neighbors for synchronous pre-paint repair.
  • Preserve existing React roots and pending form actions when containers are moved, removed, or emptied while their host blocks remain connected. Detached host subtrees are unmounted and get fresh roots if reattached.
  • Keep full maintenance on source/session invalidation and the 1-second safety sweep, plus the initial scan, rotation sweep, discovery budget, and safety exclusions.

The observer still filters composer/plugin-owned mutations per record, including mixed batches. Removed-only code-body updates remain discoverable. Discovery of child-list targets is limited to code/tag-text contexts, avoiding irrelevant host-row discovery targets generated by plugin-container insertion.

Regression evidence

The new tests use real React roots and MutationObserver in jsdom. The operation-count fixtures preserve real rAF and suppress only the explicit 1-second safety interval. The pre-frame repair test additionally holds rAF callbacks to assert that repair completes before a frame.

On unchanged upstream e64819af5968cf98e8bd28fd72a1cda977309214, the same final 11-test regression file gives 5 expected failures and 6 passes:

  • With 5 mounted labelled fences, one body update reads the other 4 bodies once each and makes 8 selector calls on those untouched blocks.
  • With 25 mounted labelled fences, it reads the other 24 bodies once each and makes 48 selector calls on those untouched blocks.
  • The fixed version records 0 untouched-body reads and 0 untouched-block selector calls in both fixtures.

Coverage also includes diagnostics, sibling insertion/removal/replacement, detached multi-root wrappers, pre-frame wipe/reparent repair, preserved input/action state, removed-only bodies, language/streaming transitions, source/session invalidation, and the full slow-sweep fallback. These are operation counts in synthetic fixtures, not elapsed-time benchmarks.

Validation

  • Node 24.19.0, pnpm 11.25.0; locked dependencies, no dependency changes.
  • pnpm run check: typecheck, 104 test files / 1349 tests, build, and standalone bundle checks passed with one Vitest worker. Two additional regressions and direct body-read assertions were then added; the final focused run passed 3 files / 125 tests, including all 113 existing DOM-fence tests, 11 new maintenance tests, and the rAF-cleanup test. The implementation logic was unchanged during these runs.
  • node scripts/verify-pack.mjs: passed, 3.29 MB tarball / 10.82 MB unpacked / 236 files. Only process-local worker/heap/cache settings were used after resource-limited attempts; package limits and scripts were unchanged.
  • git diff --check: passed.
  • Separate validation reran all 11 final maintenance tests and the two unchanged discovery-budget regressions successfully.
  • A supplemental Chromium check could not run: the default-sandbox browser terminated before page load with SIGABRT and environment socket/crashpad errors. Browser assertions did not execute. No sandbox disabling or permission expansion was attempted.

Limits and follow-up

Source notifications deliberately retain full invalidation. A host that publishes a source snapshot for every token may therefore still perform O(M) maintenance per token. Large structural changes can still traverse the changed subtree synchronously; this is not a hard frame-time guarantee. The anchorless ordinal cache, Safari-specific behavior, real DSH host/model integration, and the original Windows/display-plugin frame-rate/INP report are not claimed as verified or fixed here.

AI assistance was material to implementation, test design, and review. The resulting diff and evidence also received a separate review; no human review is implied by that statement.

Track dirty mounts and diagnostics while preserving full source/session
invalidation and the slow safety sweep. Add regression coverage for
operation counts, structural recovery, and retained input/action state.

Refs omdsh-dev#321

AI-assisted implementation, tests, and review.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T07:54:03.828517Z 01ee63d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@taekchef
taekchef merged commit 2ec9473 into omdsh-dev:main Oct 21, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants