-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Description
Problem
Currently, when loading a task (either new or from history), all messages are sent to the webview at once through postStateToWebview(). This can cause memory issues and UI freezing when dealing with tasks that have a large number of messages.
In ClineProvider.ts:1669, the entire message array is sent:
clineMessages: this.getCurrentCline()?.clineMessages || [],Proposed Solution
Implement lazy loading for task messages where:
- Only a limited number of messages (e.g., the most recent 50-100) are initially sent to the webview
- The webview can request additional messages as needed (e.g., when scrolling up)
- Messages are loaded in batches to avoid memory overload
Implementation Details
Backend Changes
-
Modify
getStateToPostToWebview()to send only a subset of messages:// Instead of sending all messages clineMessages: this.getCurrentCline()?.clineMessages || [], // Send only recent messages clineMessages: this.getCurrentCline()?.clineMessages.slice(-INITIAL_MESSAGE_LIMIT) || [],
-
Add a new message handler in
webviewMessageHandler.tsto handle requests for more messages:case "loadMoreMessages": const messages = provider.getCurrentCline()?.clineMessages || [] const startIndex = message.startIndex || 0 const batch = messages.slice(startIndex, startIndex + MESSAGE_BATCH_SIZE) await provider.postMessageToWebview({ type: "additionalMessages", messages: batch, hasMore: startIndex + MESSAGE_BATCH_SIZE < messages.length }) break
-
Track message loading state in the Task class to know which messages have been sent
Frontend Changes
- Update
ExtensionStateContextto handle incremental message loading - Implement scroll detection in the chat view to trigger loading more messages when user scrolls near the top
- Add loading indicators to show when more messages are being fetched
Benefits
- Significantly reduced initial load time for tasks with many messages
- Lower memory footprint in the webview
- Better UI responsiveness
- Scalability for long-running tasks with thousands of messages
Related Work
PR #6522 attempted to implement incremental message updates for new messages, but it seems the implementation was later changed. This proposal extends that concept to handle the initial loading of messages as well.
Considerations
- Need to ensure message ordering is preserved
- Handle edge cases like messages being added while loading older ones
- Consider implementing virtual scrolling for extremely large message lists
- May need to adjust how message search/filtering works with lazy loading
Metadata
Metadata
Assignees
Labels
Type
Projects
Status