Repository navigation
perf(ui): stop rescanning every transcript link on each DOM change - #160050
Conversation
Transcript mutations repeatedly classified every anchor, including links no reader claimed and links already excluded. The reported production profile (534 messages) attributed 100 ms of 768 ms busy time to scans during 60 wheel steps (13%), 209 ms of 1167 ms during 24 resize steps (18%), 88 ms across 300 streaming deltas, and 20 ms across four session switches. The exclusion gate accounted for 80-85% of scan cost. Resolve the reader claim and preview method before the unchanged shared isPreviewAnchor gate. providerFor only finds an existing nearest provider; reader resolution and exclusion are synchronous predicates, so reordering their conjunction preserves hover/focus/prefetch eligibility. Keep positive and negative classifications in a directive-owned WeakMap, keyed by current href and reader-array identity. Mutation records invalidate moved subtrees and changed exclusion attributes; each scan also checks root ancestry once. Clear the cache in the existing release lifecycle. Preserve nearest-provider ownership, current visibility for unchanged target keys, removal handling, attempted deduplication, and the eight-preview budget. The actual prefetch request still independently revalidates eligibility. This replaces duplicate observed-anchor/full-root classification while retaining cheap membership discovery. The net 75 production lines provide cache ownership and the invalidation needed to preserve exclusion rules. Tests add 167 net lines and use the real classifier instead of its old mock. Chromium 153 microbenchmark, 400 anchors / six reader claims, 20 warmups and 100 samples: mean scan time on unedited origin/main e205c9d was 1.163 ms initially and 1.157 ms after an unrelated text mutation; after this change it is 0.379 ms initially and 0.142 ms on rescan (67% / 88% lower). Medians were 1.100 / 1.100 ms before and 0.400 / 0.100 ms after. This is an isolated Vite browser microbenchmark; the production performance rig was not run. Regression proof fails before the fix for unclaimed exclusion walks and repeated positive/negative classification. Added coverage retains exclusions for file/session/download links, tooltips, hovercards, source cards, and ineligible GitHub URLs, plus href, ancestor, and reader-capability changes. Validation: all nine link-reader component suites pass (265 tests, 7.08s). The five requested browser E2E suites pass (38 scenarios, 51.29s): GitHub hovercards, page previews, reader checks, favicons, and file links. The final 29-case prefetch suite passes in 2.21s (148 ms test time in the full reader run). check-changed passes all selected checks; its first run caught a test import shadowing an existing parameter, corrected by renaming the import. No pre-existing main-side failure remained. Scoped Codex autoreview completed with no findings at its default P0 threshold.
Replace the anchor classification WeakMap, mutation-record invalidation, ancestor class snapshots, and expanded attribute filter with one pure href-to-claim Map scoped to the current readers-array identity. Clear it on reader identity changes and the existing release lifecycle. Split reader claim resolution from the shared DOM eligibility gate. The directive supplies its memoized resolver; actual prefetch uses the uncached default. Retain nearest-provider lookup, live DOM exclusion checks for claimed URLs, and original observed-anchor target/key/removal revalidation. Restore attributeFilter: ["href"], so ordinary class changes no longer produce transcript MutationObserver deliveries. Remove tests specific to DOM invalidation machinery. Retain regressions for unclaimed/detail-only URLs avoiding the exclusion walk, positive/negative claim reuse (including duplicate hrefs), fresh exclusion gating, href changes, reader capability changes, nested ownership, and original lifecycle/budgets. The new duplicate-href and ancestry-independent claim regressions fail on the previous commit and pass with this memo. The follow-up removes 36 net production lines and 37 net test lines. Combined with the preceding commit, production is +39 lines against the original main baseline, down from +75. Same Chromium 153 microbenchmark: 400 anchors, six claimed URLs, 20 warmups, 100 measured samples. Original pre-edit main means remain 1.163 ms initial and 1.157 ms rescan. The pure memo measures 0.362 ms initial and 0.160 ms rescan (medians 0.300/0.100 ms). The previous DOM cache measured 0.379/0.142 ms. The production performance rig was not run. Validation: all nine link-reader component suites pass (257 tests, 5.89s), and the five requested browser E2E suites pass (38 scenarios, 47.52s). check-changed passes all selected checks. Scoped Codex autoreview completed with no findings at its default P0 threshold.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 28, 2026, 3:26 AM ET / 07:26 UTC (Revision 3). ClawSweeper reviewWhat this changesControl UI chat prefetch caches URL claims for the current plugin reader list, checks DOM exclusions for claimed links, and adds regression coverage for link and capability changes. Merge readiness✅ Ready for maintainer review Keep this PR open for landing. Current main still performs the repeated link classification, and the submitted browser measurements support the optimization. I found no actionable correctness or security defect. Priority: P2 Review scores
Verification
How this fits togetherThe Control UI scans chat transcript links to warm plugin previews before a user hovers over them. DOM changes and plugin reader capabilities feed the scan; eligible visible links can trigger a Gateway preview request. flowchart LR
A[Chat transcript links] --> B[DOM change scan]
C[Plugin reader list] --> D[URL claim cache]
B --> D
D --> E[Live DOM eligibility]
E --> F[Visible link observer]
F --> G[Gateway preview request]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +39, Tests +130. Total +169 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep long-chat preview warming responsive while retaining live link exclusions and request-time provider validation. Do we have a high-confidence way to reproduce the issue? Yes. A long transcript with mostly unclaimed links and repeated scroll, resize, or streaming changes exercises the repeated scan on current main; the contributor reports before-and-after Chromium measurements. This review did not run the browser rig. Is this the best way to solve the issue? Yes. Reader-list identity scopes the cache, lifecycle events clear it, and both DOM eligibility and the final request are checked against current state. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d167f639a81e. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
…penclaw#160050) * perf(ui): stop rescanning every transcript link on each DOM change Transcript mutations repeatedly classified every anchor, including links no reader claimed and links already excluded. The reported production profile (534 messages) attributed 100 ms of 768 ms busy time to scans during 60 wheel steps (13%), 209 ms of 1167 ms during 24 resize steps (18%), 88 ms across 300 streaming deltas, and 20 ms across four session switches. The exclusion gate accounted for 80-85% of scan cost. Resolve the reader claim and preview method before the unchanged shared isPreviewAnchor gate. providerFor only finds an existing nearest provider; reader resolution and exclusion are synchronous predicates, so reordering their conjunction preserves hover/focus/prefetch eligibility. Keep positive and negative classifications in a directive-owned WeakMap, keyed by current href and reader-array identity. Mutation records invalidate moved subtrees and changed exclusion attributes; each scan also checks root ancestry once. Clear the cache in the existing release lifecycle. Preserve nearest-provider ownership, current visibility for unchanged target keys, removal handling, attempted deduplication, and the eight-preview budget. The actual prefetch request still independently revalidates eligibility. This replaces duplicate observed-anchor/full-root classification while retaining cheap membership discovery. The net 75 production lines provide cache ownership and the invalidation needed to preserve exclusion rules. Tests add 167 net lines and use the real classifier instead of its old mock. Chromium 153 microbenchmark, 400 anchors / six reader claims, 20 warmups and 100 samples: mean scan time on unedited origin/main f320428 was 1.163 ms initially and 1.157 ms after an unrelated text mutation; after this change it is 0.379 ms initially and 0.142 ms on rescan (67% / 88% lower). Medians were 1.100 / 1.100 ms before and 0.400 / 0.100 ms after. This is an isolated Vite browser microbenchmark; the production performance rig was not run. Regression proof fails before the fix for unclaimed exclusion walks and repeated positive/negative classification. Added coverage retains exclusions for file/session/download links, tooltips, hovercards, source cards, and ineligible GitHub URLs, plus href, ancestor, and reader-capability changes. Validation: all nine link-reader component suites pass (265 tests, 7.08s). The five requested browser E2E suites pass (38 scenarios, 51.29s): GitHub hovercards, page previews, reader checks, favicons, and file links. The final 29-case prefetch suite passes in 2.21s (148 ms test time in the full reader run). check-changed passes all selected checks; its first run caught a test import shadowing an existing parameter, corrected by renaming the import. No pre-existing main-side failure remained. Scoped Codex autoreview completed with no findings at its default P0 threshold. * perf(ui): memoize link reader claims instead of DOM classifications Replace the anchor classification WeakMap, mutation-record invalidation, ancestor class snapshots, and expanded attribute filter with one pure href-to-claim Map scoped to the current readers-array identity. Clear it on reader identity changes and the existing release lifecycle. Split reader claim resolution from the shared DOM eligibility gate. The directive supplies its memoized resolver; actual prefetch uses the uncached default. Retain nearest-provider lookup, live DOM exclusion checks for claimed URLs, and original observed-anchor target/key/removal revalidation. Restore attributeFilter: ["href"], so ordinary class changes no longer produce transcript MutationObserver deliveries. Remove tests specific to DOM invalidation machinery. Retain regressions for unclaimed/detail-only URLs avoiding the exclusion walk, positive/negative claim reuse (including duplicate hrefs), fresh exclusion gating, href changes, reader capability changes, nested ownership, and original lifecycle/budgets. The new duplicate-href and ancestry-independent claim regressions fail on the previous commit and pass with this memo. The follow-up removes 36 net production lines and 37 net test lines. Combined with the preceding commit, production is +39 lines against the original main baseline, down from +75. Same Chromium 153 microbenchmark: 400 anchors, six claimed URLs, 20 warmups, 100 measured samples. Original pre-edit main means remain 1.163 ms initial and 1.157 ms rescan. The pure memo measures 0.362 ms initial and 0.160 ms rescan (medians 0.300/0.100 ms). The previous DOM cache measured 0.379/0.142 ms. The production performance rig was not run. Validation: all nine link-reader component suites pass (257 tests, 5.89s), and the five requested browser E2E suites pass (38 scenarios, 47.52s). check-changed passes all selected checks. Scoped Codex autoreview completed with no findings at its default P0 threshold.
What Problem This Solves
Long chats with many links do unnecessary main-thread work whenever scrolling, streaming, or resizing changes the transcript DOM.
The link-reader prefetch directive watches the transcript with a MutationObserver and, on every DOM change (virtualized row mount/unmount while scrolling, each streaming delta, resize re-renders), rescanned every link. For each link it first ran the DOM exclusion gate
isPreviewAnchor(URL parse, GitHub eligibility, a selector-list match on the link and on every composed ancestor up to the document) and only then asked whether any link reader even claims the URL. Links no reader claims were never remembered, so they were re-classified on every scan. In a 534-message transcript this was 13% of scroll main-thread CPU and 18% of resize CPU.User Impact
Scrolling, resizing and streaming long chats with many links do noticeably less main-thread work; link previews behave the same. No configuration changes or migration are required.
Why This Change Was Made
Resolve the reader claim first (pure: URL + the provider's reader list) and run the DOM exclusion gate only for claimed links; memoize claims by href for one reader-list identity (cleared on the directive's existing release/session/provider resets). DOM exclusions stay live on every scan;
isPreviewAnchoritself (shared with hover/focus) is unchanged, and the actual prefetch request still revalidates eligibility independently. The MutationObserver still only watcheshrefattributes.Evidence
Chromium microbenchmark, 400 links / 6 reader-claimed, mean
scan(): initial 1.163 ms → 0.362 ms; rescan after an unrelated mutation 1.157 ms → 0.160 ms.Production-bundle rig (mocked Gateway, 534-message transcripts, source-mapped CPU profiles, base e205c9d), inclusive
scan()time per scenario: scroll (60 wheel steps) 94.5 ms → 8.5 ms; resize (24 steps) 217 ms → 16 ms; streaming (300 deltas) 74 ms → 16 ms; 4 session switches 16 ms → 5.5 ms. Sampled main-thread busy time: scroll 734 → 664 ms, resize 1120 → 897 ms.Tests: 9 link-reader suites (257 tests), e2e github-link-hovercard, link-hover-preview, link-reader-checks, link-favicons, chat-file-links (38 scenarios);
check-changedgreen; regressions fail on the base (unclaimed links running the exclusion walk; claims re-parsed on rescan) and cover excluded claimed links, href changes and reader-capability changes.Focused test cost measured for landing:
pnpm test ui/src/components/link-reader-prefetch.test.ts --maxWorkers=1passed all 21 tests in 12.91 seconds wall time (/usr/bin/time -p; Vitest duration 8.60 seconds, test runner shard 11.55 seconds). This measures the complete test file, including the new regressions and wrapper startup. On the updated head, all 21 tests passed in CI job checks-ui (1/3): the per-file test duration was 0.097 seconds (96.961 ms from the Vitest module timing diagnostic). The shared CI job took 429 seconds including setup and its other tests; that total is not the added regression cost.The combined diff was reviewed and received a scoped-clean Codex autoreview at P2. The existing performance and broader test evidence above is retained from preparation; landing reran the focused cost measurement and
git diff --check. The link-reader change remains unchanged after updating the PR branch from main; no local rebase was used. This changes scan cost without changing visual appearance or rendered UI states.Landing CI recovery
The initial CI run 36370980101 failed in
checks-node-compact-small-3: workflow-planning fixtures could not find.ci-harness/scripts/ci-static-step.sh. This was a main-side CI break, confirmed fixed on main at a08479ace1d4. The lead reran the exact failing tests on that commit: 10 passed. There was no link-reader defect and the performance fix is unchanged.The PR branch was updated once through GitHub's update-branch endpoint to include the main-side repair and create a fresh merge ref. New head:
78287f384e38f19e755f9762d403e05d909c6ded. No local rebase or plain rerun was used. The fresh CI run 36390984693 completed successfully: 37 jobs passed, includingopenclaw/ci-gate, 21 were skipped, and none failed. No failed-job rerun was needed. Squash-merged asff8c752d852f5d01da5a8a5e6abb7546c1328e83.