Glob search uses 100% of CPU
Description
Everytime i use opencode to do something on my system, regarless of what it is, if it needs to search for a file it uses glob, or the RG process. This uses 100% of my CPU, i dont know why.
OpenCode version
OpenCode 1.0.134
Steps to reproduce
1-Open opencode. 2-Ask to search and open or edit a file 3-It uses Glob for the task 4-Using btop as a task manager a RG process appears and uses 100% of CPU.
Screenshot and/or share link
No response
Operating System
Im using Garuda Linux
Terminal
Cool Retro Term or Kitty Terminal
This issue might be a duplicate of existing performance-related issues. Please check:
- #4804: High CPU usage when idle or switching sessions
- #811: Text rendering is VERY slow with high CPU usage even when idle
- #2083: High CPU usage from text animation/rendering, affecting all cores
- #3176: High CPU usage from git operations (session snapshots with git add)
These issues describe similar symptoms of excessive CPU usage in OpenCode. Feel free to check if any of these address your specific case or if yours is a distinct issue with the glob/RG process specifically.
@ArmoredBear @rekram1-node a couple questions on the topic:
- Does CPU stay at 100% for several seconds, or is it just a brief spike? Rough duration?
- What are the biggest directories in the repo (e.g., node_modules, .cache, vendor, build/output dirs)?
- Please run from project root and share outputs:
- time rg --files --hidden --glob '!.git/*'
- find . -maxdepth 3 | wc -l
- Which task triggered it (/read, /open, /edit, etc.), and the exact prompt if possible?
I also have an open PR if you have time you can checkout into it and see if it solves (its a mitigation rn instead of perf fix bc there could be many ways to take this deep dive): https://github.com/sst/opencode/pull/5266
Its not a spike, or for several seconds, when i tell opencode using grok code fast to search for a file it does recursively and keeps my CPU at 100% until either a ask it to stop, kill opencode or restart my computer! Most of the time i need to restart my computer!
There is no exact prompt, when i simply tell opencode to edit a file and add some text or search for something and open this happens! And its random! sometime s it happens and when it does opencode hangs, as like its thinking and nothing happens for a long time and then CPU its a 100%. then i kill it or restar my computer and then it does not happen again for some time, but its very frequent. Like for 5 prompts 3 of them happen.
@ArmoredBear I am taking a deep dive into the CPU/glob I might have found the issue but I cannot reproduce this on my side for some reason so I am wondering if you can checkout into my open PR and still see if you reproduce the errors from your side.
Please at your earliest chance try and checkout into branch feat/glob-cpu-cap and run your normal ‘search/open/edit’ flow. Do you still get sustained 100% CPU? If yes, did you enable follow?If so disable it and try again. If it only happens with follow, I’ll ship a safe follow implementation next. How big of a codebase are you searching / any patterns like "" / "/*" in parallel?
Where I think error is in --follow tag(symlink looping): https://unix.stackexchange.com/questions/99159/is-there-an-algorithm-to-decide-if-a-symlink-loops https://stackoverflow.com/questions/14569390/why-do-i-have-an-infinite-recursion-loop-happening-with-these-symlinks https://github.com/nextcloud/desktop/issues/6711
If this is true I will not rely on rg --follow and create a walk with lstat to keep track of symlink inodes visited to not continuously loop/chase forever... however if it is not pls let me know any more info you can on this issue, ty!
Look, im really a beginner on this stuff, so i dont know how to do what you asking. Sorry. Im just using the tool to help me with developing a game with C#, but when i ask to search for a script or file the problem keeps happening, ill tell you that it only happens when Glob, RipGrep or Grep are used, in which checking for usage of CPU using btop on my terminal it shows RG process consuming 100% of CPU and does not stop until i kill the process, basically every time i need to use the tool i need to specify for it to not use anything that uses rg process. Now, the commands "list" and "find" when not using rg process get a bit slow on the search itself which is fine by me, but it does not lag anything and does not use 100% of CPU. Also, when rg is used the tool hangs and does nothing for a long period of time, then stops, does not find what i want and CPU keeps at 100%. Sorry i will not be able to do what you want, so i hope this information will help you