Problem
In ai-chat-panel.tsx, the collectFilePaths() function is called on every render inside the useChat() body configuration. This function traverses the entire virtual file system tree to build a flat list of all file paths. In large projects with many files, this is an unnecessary and expensive operation that runs on every keystroke and every streaming token received.
Proposed Fix
Wrap the call in useMemo:
const filePaths = useMemo(
() => collectFilePaths(fileTree),
[fileTree]
);
This ensures file path collection only re-runs when the actual file tree changes, not on every render.
Impact
- Reduces unnecessary CPU usage during AI streaming
-
- Improves typing responsiveness in the chat input
-
-
- Scales better as project file count grows
Problem
In
ai-chat-panel.tsx, thecollectFilePaths()function is called on every render inside theuseChat()body configuration. This function traverses the entire virtual file system tree to build a flat list of all file paths. In large projects with many files, this is an unnecessary and expensive operation that runs on every keystroke and every streaming token received.Proposed Fix
Wrap the call in
useMemo:This ensures file path collection only re-runs when the actual file tree changes, not on every render.
Impact