opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix(grep): stream ripgrep output to prevent memory exhaustion

Open Hona opened this issue 1 month ago • 0 comments

rg runs on some really common string on some large search space e.g. cd / && rg / it waits for ALL the results to finish... It used to load all the results (imagine 1 GB of text) all into memory. Then string split, (allocating another 1+ GB of memory). It would also do stat calls for all results Then finally only fetch the first 100.

Now when you do sinful rg it returns instantly and saves your memory/disk for better things.

Note: There would be a behavior regression here - it used to load all results and when truncating to 100 it is sorted by recently modified We could do a hybrid approach here - allow streaming in 2000(?) results and return the most recent 100 out of that (killing rg) to limit worst case, but still provide a good experience for small search results.

image

Hona avatar Dec 12 '25 09:12 Hona