Skip to content

fix: reduce UI performance degradation in long conversations#12459

Open
ajayjha1 wants to merge 1 commit into
continuedev:mainfrom
ajayjha1:fix/chat-ui-performance-degradation
Open

fix: reduce UI performance degradation in long conversations#12459
ajayjha1 wants to merge 1 commit into
continuedev:mainfrom
ajayjha1:fix/chat-ui-performance-degradation

Conversation

@ajayjha1
Copy link
Copy Markdown

@ajayjha1 ajayjha1 commented May 22, 2026

Title: fix: reduce UI performance degradation in long conversations (#12053)


  • Memoize findLatestSummaryIndex with useMemo to fix O(n²) per-render scan
  • Extract per-message rendering into MemoizedHistoryItem (React.memo) so stable messages are skipped during streaming token updates
  • Pre-compute lastUserInputIndex with useMemo keyed on history.length
  • Remove per-child ResizeObserver loop in useAutoScroll; observe only container
  • Wrap StepContainer and TimelineItem with React.memo

Fixes #12053

Description

In long conversations (500k+ tokens), the chat UI becomes progressively slower due to several compounding render inefficiencies:

  • findLatestSummaryIndex was called inside the per-item render callback, making every full re-render O(n²) — it scanned the entire history once per message.
  • No message-level memoization meant every streaming token caused all history items to re-render, even ones whose content hadn't changed.
  • isLastUserInput captured the full history array in its closure and rescanned it on every call.
  • useAutoScroll attached a ResizeObserver to every child DOM node — with hundreds of messages this created hundreds of observers firing on every token.

These changes fix each issue without requiring virtual scrolling, keeping the diff minimal and safe.

Checklist

Screen recording or screenshot

Tested manually with a multi-turn conversation. Scrolling, streaming, and compaction display all behave correctly after the fix. A before/after profiler trace would show significantly fewer component re-renders per streaming token in long sessions.

Tests

No new tests added — the fix is purely in render/memoization logic with no changes to business logic, selectors, or reducers. Existing behaviour is preserved; only unnecessary re-renders are eliminated.


Summary by cubic

Reduce chat UI lag in long conversations by cutting O(n²) scans and avoiding unnecessary re-renders during streaming. Keeps long threads responsive; fixes #12053.

  • Bug Fixes
    • Memoized findLatestSummaryIndex with useMemo to remove O(n²) per-render scans.
    • Added MemoizedHistoryItem with React.memo so stable messages don’t re-render on each token.
    • Computed lastUserInputIndex with useMemo keyed to history.length.
    • Wrapped StepContainer and TimelineItem with React.memo.
    • Simplified useAutoScroll to observe only the container instead of each child.

Written for commit 3351a0d. Summary will update on new commits. Review in cubic

- Memoize findLatestSummaryIndex with useMemo to fix O(n²) per-render scan
- Extract per-message rendering into MemoizedHistoryItem (React.memo) so
  stable messages are skipped during streaming token updates
- Pre-compute lastUserInputIndex with useMemo keyed on history.length
- Remove per-child ResizeObserver loop in useAutoScroll; observe only container
- Wrap StepContainer and TimelineItem with React.memo

Fixes continuedev#12053
@ajayjha1 ajayjha1 requested a review from a team as a code owner May 22, 2026 06:05
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label May 22, 2026
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

UI becomes extremely slow in long conversations

1 participant