perf: parallelize filestamp collection and context-mode search - #72
Merged
Conversation
1. collect_filestamps (meta.rs): Replace sequential fs::metadata loop with rayon par_iter for 2-4x speedup on large repos (I/O-bound). 2. Context-mode search (serve.rs): Use par_iter().enumerate() + sort instead of sequential iter() when context lines are requested, preserving file order while enabling parallel matching. Fixes #70 Fixes #71 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves performance in two hot paths by parallelizing work that was previously done sequentially: filesystem metadata (filestamps) collection during index build, and context-mode search matching in the server while preserving output order.
Changes:
- Parallelize
collect_filestamps()intgrep-coreusing Rayon to speed up per-filefs::metadata()calls. - Parallelize context-mode search in
tgrep serveand restore deterministic file order after parallel matching.
Show a summary per file
| File | Description |
|---|---|
| tgrep-core/src/meta.rs | Collect filestamps in parallel via Rayon to reduce sequential I/O time. |
| tgrep-cli/src/serve.rs | Run context-mode matching in parallel and re-establish original file ordering before emitting results. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
par_iter() on an indexed Vec already preserves order when collecting, so the enumerate() + sort_unstable_by_key() was redundant. Replaced with a simpler map-to-Vec<Vec> + flatten approach. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
baopingz
approved these changes
Apr 22, 2026
baopingz
approved these changes
Apr 22, 2026
Shengyu Fu (shengyfu)
added a commit
that referenced
this pull request
Apr 23, 2026
Includes performance improvements from PRs #67-#74: - Glob filter using globset crate (#67) - Lazy-cached builtin file types (#68) - HashSet-based trigram extraction (#69) - Parallel filestamps and context search (#72) - Cache read-lock contention fix (#74) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Summary
Two parallelization improvements that eliminate unnecessary sequential I/O and computation.
Changes
1. Parallel filestamp collection (meta.rs)
\collect_filestamps()\ previously looped sequentially over all indexed paths calling \s::metadata(). Now uses
ayon::par_iter()\ for parallel metadata collection. Expected 2-4x speedup on large repos where this is I/O-bound.
2. Parallel context-mode search (serve.rs)
Context-mode searches (-B/-A\ flags) previously fell back to sequential \iter()\ to preserve output ordering. Now uses \par_iter().enumerate()\ + sort by index to restore file order while keeping parallel matching. Expected 4-8x speedup for context searches.
Testing
All 108 existing tests pass. No new dependencies added (
ayon\ already in use).
Fixes #70
Fixes #71