Skip to content

perf: eliminate composer #/@ mention menu typing lag - #1307

Merged
iruriQ merged 1 commit into
mainfrom
fix/hash-mention-input-lag
Nov 27, 2026
Merged

iruriQ merged 1 commit into
mainfrom
fix/hash-mention-input-lag

Conversation

@iruriQ

@iruriQ iruriQ commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

Eliminate severe typing lag when typing # / @ in the Composer to open the delegation/command/skill/thread/file mention menu across both Web UI and Codex Desktop (renderer-extension).

Root Causes & Fixes

  1. Coalesce K × S candidate refetches (ui-input-trigger/src/client/controller.ts):
    • Coalesce same-turn invalidation callbacks into a single microtask and refetch only the invalidated sources, using per-source AbortController entries while preserving generation & abort guards so unrelated in-flight sources are never aborted or redundantly re-queried.
  2. Debounce & deduplicate workspace file reference searches (ui-sidebar-files/src/client/file-mentions.ts):
    • Add a 135ms debounce (FILE_MENTION_DEBOUNCE_MS) around remote.fileReferences.list, immediately cancelling prior AbortSignals during rapid typing, plus in-flight deduplication per (sessionId, query) without slowing down local Agent/command/skill filtering.
  3. Cache derived Thread index & cap non-empty search results (ui-codexhost/src/client/thread-reference-discovery.ts):
    • Cache archived set, workspace label map, and sorted/lowercased Thread index by snapshot reference so per-keystroke filtering avoids O(W + T + M log M) rebuilds.
    • Cap non-empty query results at NON_EMPTY_QUERY_THREAD_LIMIT (25) to avoid mounting hundreds of option DOM nodes.
  4. Narrow MenuView geometry & sticky-group observer dependencies (MenuView.tsx, useAnchoredMaxHeight.ts, MenuGroup.tsx):
    • Pass state.open (instead of the entire state object) to useAnchoredMaxHeight, observe the composer card/parent via ResizeObserver, ignore scroll events originating inside the menu itself, and keep listeners stable while mounted.
    • Add useStickyMenuGroups and track mounted <MenuGroup> key structure so IntersectionObserver / ResizeObserver are rebuilt only when group structure changes.
  5. Stabilize Agent icon component identity (ui-codexhost/src/client/harness-discovery.tsx):
    • Cache harnessAgentIcon(harnessId, hostId) components by icon identity instead of allocating new inline functions on every .map(), preventing per-keystroke SVG / RemotePluginIcon remounts.
  6. Defer Web trigger tracking during IME composition & debounce draft persistence (ui-conversation/src/client/input/editor/runtime.ts, facade.ts):
    • Defer inputTriggers.track(...) during compositionstart–compositionend and immediately flush on compositionend.
    • Coalesce synchronous persistDraft (localStorage.setItem + JSON.stringify) writes with a 180ms debounce (DRAFT_PERSIST_DEBOUNCE_MS), flushing immediately on send (submit / commitDraft), session switch (unbind), pagehide / beforeunload, persistCurrentDraft, and dispose.
  7. Remove heavy 40px backdrop blur from high-frequency trigger menu (MenuView.module.css, MenuSurface.tsx, MenuSurface.module.css):
    • Add material="solid" on MenuSurface (skipping backdrop-filter: blur(40px) saturate(150%) and the macOS .backing portal) and apply crisp opaque light (rgb(248, 249, 250)) and dark (rgb(48, 49, 54)) fills in MenuView.module.css.
  8. Optimize Desktop injected # menu hot path (packages/renderer-extension/src/renderer-delegation-mention.ts, renderer-binding-probe.ts):
    • Coalesce same-frame input / selectionchange events and skip render() on sameQuery when the catalog fingerprint is unchanged.
    • Batch layout reads before DOM/style writes in render() and invoke scrollIntoView only when activeIndex actually changes.
    • Ignore injected delegation mention menu & style mutations in mutationMayAffectComposer to avoid triggering full-document Composer scans on menu updates.

Visual Verification

Captured and inspected rendered Playwright screenshots of the real MenuView + theme stylesheets over dense transcript/code content in both light and dark modes (1024×760 @2x):

  • Light mode: data-menu-material="solid", backdrop-filter: none, background-color: rgb(248, 249, 250), crisp hairline border + prominent elevation shadow, zero bleed-through over code blocks behind the menu, zero clipping (backingCount: 0).
  • Dark mode: data-menu-material="solid", backdrop-filter: none, background-color: rgb(48, 49, 54), clear rgba(255, 255, 255, 0.16) hairline border + shadow separation over dark transcript, clean section headers and highlight contrast, zero bleed-through or clipping (backingCount: 0).

Validation

  • Focused unit tests (10 test files, all passed):
    • apps/web-ui/packages/client/ui-input-trigger/test/lexicon-notifications.test.ts
    • apps/web-ui/packages/client/ui-sidebar-files/test/file-mentions.test.ts
    • apps/web-ui/packages/client/ui-codexhost/test/thread-reference-discovery.test.ts
    • apps/web-ui/packages/client/ui-codexhost/test/harness-discovery-icons.test.ts
    • apps/web-ui/packages/client/ui-codexhost/test/harness-discovery.test.ts
    • apps/web-ui/packages/client/ui-conversation/test/draft-persistence-and-ime.test.ts
    • apps/web-ui/packages/client/ui-conversation/test/draft-editor-text-ref.test.ts
    • apps/web-ui/packages/client/ui-conversation/test/keymap-enter.test.ts
    • packages/renderer-extension/test/renderer-delegation-mention.test.ts
    • packages/renderer-extension/test/renderer-skill-library.test.ts
  • npx tsc --noEmit -p apps/web-ui/tsconfig.json — passed
  • npx tsc -b packages/renderer-extension — passed
  • npx prettier --check (all 22 changed files) — passed
  • npm run build:web:ui — passed

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@iruriQ
iruriQ merged commit 3b19f8b into main Nov 27, 2026
4 of 8 checks passed
@iruriQ
iruriQ deleted the fix/hash-mention-input-lag branch November 27, 2026 08:05
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