Home

mweinbach / agent-coworker

publicmweinbach/agent-coworker
Overview Code History Branches Pull requestsIssuesInsights
main
HomeOverview Code PRsIssues

perf(desktop): frontend optimization - memoization, debouncing, feed caps

9 months ago

003c0a7
Authored
mweinbach2/10/2026, 12:51:36 AM
Phase 2 of the desktop audit: frontend performance improvements.

**React memoization (Findings 7.2, 7.3):**
- Wrap FeedRow and Markdown components in React.memo to prevent
  re-rendering unchanged chat bubbles when the feed grows
- Move remarkGfm and rehypeSanitize plugin arrays to module-level
  constants so ReactMarkdown doesn't re-parse on every render
- Stabilize composer onKeyDown handler with useCallback

**Zustand selector narrowing (Finding 7.1):**
- ChatView: replace broad `threads` and `threadRuntimeById` selectors
  with narrow ones that only return the selected thread's data. This
  prevents the entire chat view from re-rendering when unrelated
  threads change
- ChatView: replace `promptModal` object selector with boolean
  `hasPromptModal` to avoid unnecessary re-renders from object
  identity changes

**Debounced state persistence (Finding 8.1):**
- Replace synchronous persist() with a 300ms debounced version that
  batches rapid state saves (e.g. during fast message exchanges)
- Critical writes (thread creation, workspace changes) use persistNow()
  to ensure data is written before continuing

**Batched transcript writes (Finding 8.2):**
- Replace individual appendTranscriptEvent IPC calls with a 200ms
  batched appendTranscriptBatch that groups events by thread_id and
  writes them in a single file operation via the new Rust batch API
- Remove now-unused appendTranscriptEvent import

**Bounded collections (Findings 8.3, 8.4):**
- Cap feed arrays to MAX_FEED_ITEMS (2000) to prevent unbounded memory
  growth in long-running threads. Older items are trimmed from the start
- Cap notifications to MAX_NOTIFICATIONS (50) via pushNotification()
  helper, applied to all 8 notification append sites

**Auto-scroll improvement:**
- Only auto-scroll to bottom when user is within 200px of the bottom,
  preventing jarring jumps when reading history

**PromptModal state fix (Finding 9.1):**
- Reset freeText input when a new ask prompt appears, preventing stale
  text from carrying over between consecutive question prompts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Parent7ad2863

3 files changed
  • apps/desktop/src/app/store.ts+103−46
  • apps/desktop/src/ui/ChatView.tsx+43−19
  • apps/desktop/src/ui/PromptModal.tsx+7−1