[PR #5432] fix(grep): stream ripgrep output to prevent memory exhaustion #11402

Closed
opened 2026-02-16 18:16:14 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5432

State: closed
Merged: No


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
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5432 **State:** closed **Merged:** No --- 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. <img width="1304" height="947" alt="image" src="https://github.com/user-attachments/assets/4ba70cc9-8eda-4aeb-ac6e-0b6100aca153" />
yindo added the pull-request label 2026-02-16 18:16:14 -05:00
yindo closed this issue 2026-02-16 18:16:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11402