perf(grep): speed up files_with_matches via ripgrep mtime sort and early-stop#968
Draft
7Sageer wants to merge 1 commit into
Draft
perf(grep): speed up files_with_matches via ripgrep mtime sort and early-stop#9687Sageer wants to merge 1 commit into
7Sageer wants to merge 1 commit into
Conversation
Delegate most-recently-modified-first ordering to ripgrep via --sortr modified, then read records incrementally and kill the subprocess as soon as head_limit non-sensitive matches are collected. This removes the per-file stat pass from JS and avoids a full tree scan for broad patterns. content and count_matches keep the buffered path. The files_with_matches truncation notice no longer reports an exact total, since the search stops early.
🦋 Changeset detectedLatest commit: 16742d2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Related Issue
No related issue.
Problem
The Grep tool's default
files_with_matchesmode stat-ed every matching file from JS to sort by mtime, then discarded everything beyondhead_limit. That is one (cross-channel, on remote Kaos / SSH backends) round-trip per matched file, so a broad pattern in a large repository could make a single grep call slower than an LLM inference. It also always scanned the whole tree even when only the first page of results was needed.What changed
files_with_matchesnow runs ripgrep with--sortr modified, so ripgrep emits matches in most-recently-modified-first order.head_limitnon-sensitive matches are collected, so broad patterns no longer force a full scan or per-file stat calls from JS.contentandcount_matcheskeep the existing buffered path (and their exact totals).files_with_matchestruncation notice reportsmore availableinstead of an exact total.Added tests for the early-stop behavior and removed the now-obsolete JS stat-sort tests.
Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.