fix(core): avoid recursive scan when browsing directories in Open Project#31306
Open
ysm-dev wants to merge 1 commit into
Open
fix(core): avoid recursive scan when browsing directories in Open Project#31306ysm-dev wants to merge 1 commit into
ysm-dev wants to merge 1 commit into
Conversation
…ject The Open Project picker browses arbitrary, non-project locations (/, /usr, deep paths). For those, find() fell through to a full recursive rg --files scan, spawning many ripgrep processes and spiking CPU/memory while the web modal hung on Loading. The bounded shallow scan only triggered for the exact home directory. Use that shallow listing for directory-type finds in global locations; @-mention file search in real projects is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #15334 (exact root cause; was folded into the memory megathread #20695). Related: #22655.
Type of change
What does this PR do?
The Open Project picker can browse any location the server can see, including non-project roots like
/,/usr,/var, or a deep~/projects/org/repo. For those,FileSystem.findfell through to a full recursiverg --filesscan of the entire tree. That spawns many ripgrep processes, spikes CPU/memory (the linked issue saw 12rgprocesses and a 350MB→7.9GB jump while "scanning entire /var" and "/usr"), and leaves the web "Open Project" modal stuck on Loading.There was already a bounded, shallow (2-level) directory scan, but it only triggered for the exact home directory. This PR uses that same shallow listing for directory-type finds in non-project (global) locations. The picker only needs immediate folder names to let you browse, so nothing is lost. File search (
@-mentions) inside real git projects is unchanged — it still uses the full recursive scan.The change is two lines in
packages/core/src/filesystem.ts:scan()gains ashallowflag, andfind()sets it whentype === "directory"and the location is global.How did you verify your code works?
packages/core/test/location-search.test.ts: it createsalpha/nested/deep+beta, then asserts a globaltype: "directory"find returnsalpha,alpha/nested, andbetabut not the third-levelalpha/nested/deep(proving it stays shallow rather than recursing).bun test test/location-search.test.tsfrompackages/core→ 12 pass.bun typecheckfrompackages/core→ clean.Screenshots / recordings
N/A — no UI changes.
Checklist
Note: this code was written with GPT-5.5.