[Bug]Deep clone of entire message history causes 30+ second delay with 200 messages #7304

Open
opened 2026-02-16 18:06:46 -05:00 by yindo · 1 comment
Owner

Originally created by @illuxiza on GitHub (Jan 23, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Deep clone of entire message history causes 30+ second delay with 200 messages

Description

In long sessions (~200 messages), sending a new message takes 30+ seconds before getting any response. The delay is caused by a deep clone of the entire message history on every loop iteration.

Location

packages/opencode/src/session/prompt.ts, line 573:

const sessionMessages = clone(msgs)

Why this is slow

The clone() function from remeda recursively copies:

  • Every message object
  • Every part (text, tool calls, attachments)
  • All nested content including large tool outputs

With 200 messages × 5 parts each = 1000+ objects deep cloned per iteration.

Plugins

No response

OpenCode version

Latest

Steps to reproduce

  1. Build up a session with 100+ messages (long refactoring task)
  2. Send a new message
  3. Wait 30+ seconds before the model starts responding
  4. Observe the delay increases with message count

Screenshot and/or share link

No response

Operating System

macOS 26.2

Terminal

wave

Originally created by @illuxiza on GitHub (Jan 23, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description # Deep clone of entire message history causes 30+ second delay with 200 messages ## Description In long sessions (~200 messages), sending a new message takes **30+ seconds** before getting any response. The delay is caused by a deep clone of the entire message history on every loop iteration. ## Location `packages/opencode/src/session/prompt.ts`, line 573: ```typescript const sessionMessages = clone(msgs) ``` ## Why this is slow The `clone()` function from `remeda` recursively copies: - Every message object - Every part (text, tool calls, attachments) - All nested content including large tool outputs With 200 messages × 5 parts each = 1000+ objects deep cloned per iteration. ### Plugins _No response_ ### OpenCode version Latest ### Steps to reproduce 1. Build up a session with 100+ messages (long refactoring task) 2. Send a new message 3. Wait 30+ seconds before the model starts responding 4. Observe the delay increases with message count ### Screenshot and/or share link _No response_ ### Operating System macOS 26.2 ### Terminal wave
yindo added the bugperf labels 2026-02-16 18:06:46 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 23, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #9930: Add configurable scrollback/message limit to reduce TUI lag - addresses performance issues with long message histories
  • #6172: High CPU usage (100%+) during LLM streaming in long sessions due to O(n) text buffer rendering - comprehensive analysis of performance degradation with session length
  • #3746: Long prompt history stalls the app, long load time - reports slowdowns with accumulated message history

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 23, 2026): This issue might be a duplicate of existing issues. Please check: - #9930: Add configurable scrollback/message limit to reduce TUI lag - addresses performance issues with long message histories - #6172: High CPU usage (100%+) during LLM streaming in long sessions due to O(n) text buffer rendering - comprehensive analysis of performance degradation with session length - #3746: Long prompt history stalls the app, long load time - reports slowdowns with accumulated message history Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7304