Skip to content

perf(ui): stop rescanning every transcript link on each DOM change - #160050

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-ui-link-prefetch-scan
Sep 28, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-ui-link-prefetch-scan

Conversation

@steipete

@steipete steipete commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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; isPreviewAnchor itself (shared with hover/focus) is unchanged, and the actual prefetch request still revalidates eligibility independently. The MutationObserver still only watches href attributes.

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-changed green; 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=1 passed 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, including openclaw/ci-gate, 21 were skipped, and none failed. No failed-job rerun was needed. Squash-merged as ff8c752d852f5d01da5a8a5e6abb7546c1328e83.

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.
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete enabled auto-merge (squash) September 28, 2026 02:45
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 28, 2026, 3:26 AM ET / 07:26 UTC (Revision 3).

ClawSweeper review

What this changes

Control 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
Reviewed head: 78287f384e38f19e755f9762d403e05d909c6ded

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Measured browser-path performance and targeted regressions support a narrow optimization with no identified merge defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The changed Control UI prefetch directive was exercised through a Chromium production-bundle chat rig with a mocked Gateway and 534-message transcripts; contributor-reported after-fix scan times improved for scrolling, resizing, streaming, and session switches, with focused and browser E2E tests as supplemental coverage. The new Map is memory-only, so stored-data compatibility is not applicable.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed Control UI prefetch directive was exercised through a Chromium production-bundle chat rig with a mocked Gateway and 534-message transcripts; contributor-reported after-fix scan times improved for scrolling, resizing, streaming, and session switches, with focused and browser E2E tests as supplemental coverage. The new Map is memory-only, so stored-data compatibility is not applicable.
Evidence reviewed 7 items Introduced cache and live gate: The directive caches claims by href and reader-list identity, clears them on release, and still checks the current anchor before observing it.
Final request revalidation: The request resolves the claim without the directive cache, then checks abort, anchor, provider, client, agent, and reader identity before calling prefetch.
Provider lifecycle: Replacing the provider's reader list dispatches the capability-change event that resets the directive's cache.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +39, Tests +130. Total +169 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 54 15 +39
Tests 1 139 9 +130
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 193 24 +169

Review metrics

Metric Value Why it matters
Production versus test growth production +54/-15 lines; tests +139/-9 lines The production growth is confined to claim caching and its lifecycle; the added tests target eligibility and cache invalidation.
Focused test cost 12.91 seconds wall time The PR body measures the complete 21-test prefetch file, giving maintainers a concrete per-PR test cost.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The measured long-chat slowdown is user-facing but limited to Control UI preview scanning.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed Control UI prefetch directive was exercised through a Chromium production-bundle chat rig with a mocked Gateway and 534-message transcripts; contributor-reported after-fix scan times improved for scrolling, resizing, streaming, and session switches, with focused and browser E2E tests as supplemental coverage. The new Map is memory-only, so stored-data compatibility is not applicable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed Control UI prefetch directive was exercised through a Chromium production-bundle chat rig with a mocked Gateway and 534-message transcripts; contributor-reported after-fix scan times improved for scrolling, resizing, streaming, and session switches, with focused and browser E2E tests as supplemental coverage. The new Map is memory-only, so stored-data compatibility is not applicable.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RoboClaw: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-28T02:48:55.365Z sha 2409318 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T03:02:40.174Z sha 2409318 :: needs changes before merge. :: none

@steipete
steipete disabled auto-merge September 28, 2026 02:55
@steipete
steipete enabled auto-merge (squash) September 28, 2026 07:19
@steipete
steipete merged commit ff8c752 into main Sep 28, 2026
98 of 99 checks passed
@steipete
steipete deleted the steipete/perf-ui-link-prefetch-scan branch September 28, 2026 07:31
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 29, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant