opencode icon indicating copy to clipboard operation
opencode copied to clipboard

High CPU usage

Open shantur opened this issue 1 month ago • 10 comments

Description

I use opencode on MacOS ( Intel ) and after sometime the CPU usage keeps increasing. Even when session is idle, the CPU usage stays high.

My main usage is in 2 projects and I see the same behaviour in both.

  1. typescript, javascript, html app
  2. Dart / Flutter app

I don't use it anywhere else so not sure if this is related.

OpenCode version

1.0.110

Steps to reproduce

Unsure of the steps. Just keep using opencode, switch sessions, fork sessions etc

Screenshot and/or share link

Image

Operating System

macOS 15.7.2

Terminal

iTerm2, CodeNomad

shantur avatar Nov 26 '25 22:11 shantur

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

  • #811: Text rendering is VERY slow (and CPU usage is really high even when idle) - Closed but reports similar high CPU usage on idle
  • #2688: Opencode freezes when pressing option + left arrow key on MacBook with high CPU usage - MacBook CPU spike issue
  • #2805: High RAM usage in latest release - Related to high resource usage
  • #3013: Uses a huge amount of memory - Memory usage keeps increasing with AI use
  • #3798: OpenTUI causes crashes and heavy memory usage - opentui related resource consumption

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

github-actions[bot] avatar Nov 26 '25 22:11 github-actions[bot]

do you have permissions turned on?

thdxr avatar Nov 27 '25 02:11 thdxr

happens to me too

pablonification avatar Nov 27 '25 06:11 pablonification

do you have permissions turned on?

No permissions aren't enabled in any of the projects

shantur avatar Nov 27 '25 07:11 shantur

Just observed an agent running into this very issue on accident. Reproduction steps are as follows:

  • Asked an agent to implement some feature and trigger a build / compile afterwards.
  • Agent completed the implementation and compiled successfully, which caused our build output directory to fill up (and, due to a misconfiguration on my end, this directory is not in any .gitignore file or similar)
  • Agent noticed the huge amount of new files after checking git status and decided to remove them using rm -rf.
  • After freezing for about 30s, OpenCode's "Modified Files" sidebar started listing every single deleted file that previously existed in the now deleted directory. In this state, the TUI does not react to any key presses anymore and needs to be killed.

I submitted https://github.com/sst/opencode/pull/4963 to introduce pagination for this scenario.

andre-schaerpf avatar Dec 02 '25 00:12 andre-schaerpf

are you sure the issue was the sidebar rendering and not the diff checking? just curious

Did you use btop to figure that out

rekram1-node avatar Dec 02 '25 00:12 rekram1-node

The diff itself seems to be pretty fast - at least based on what I saw during debugging. I did not measure the timing though (also no btop). My first approach was to change the diff panel to be collapsed by default while leaving the diff logic itself unchanged. This immediately improved performance for me; at least until I manually expanded the panel again, which then caused a freeze as expected.

andre-schaerpf avatar Dec 02 '25 01:12 andre-schaerpf

Ahh okay good to know

rekram1-node avatar Dec 02 '25 01:12 rekram1-node

i'll take a look at the pr just wanted to make sure we address core issue

rekram1-node avatar Dec 02 '25 01:12 rekram1-node

What I'm seeing is quite a bit different. If I tab away from the agent for a long time, then tab back, it's quite laggy - sometimes typing is very slow, and if I press enter it will send the message without everything I typed in there. And then it won't show the agent replying until some time later (after a delay). Often I Ctrl c out of open code then reopen it and go to the session to see that the agent indeed was working and I had just interrupted it midway due to the UI lag. Maybe opencode is trying to update the display constantly when nothing is changing (while tabbed out) and this all gets buffered somehow lagging out future updates? Just a guess.

paralin avatar Dec 02 '25 02:12 paralin