Skip to content

perf: parallelize filestamp collection and context-mode search - #72

Merged
Shengyu Fu (shengyfu) merged 2 commits into
mainfrom
perf/parallel-filestamps
Apr 22, 2026
Merged

perf: parallelize filestamp collection and context-mode search#72
Shengyu Fu (shengyfu) merged 2 commits into
mainfrom
perf/parallel-filestamps

Conversation

@shengyfu

Copy link
Copy Markdown
Member

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

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>
Copilot AI review requested due to automatic review settings April 22, 2026 20:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() in tgrep-core using Rayon to speed up per-file fs::metadata() calls.
  • Parallelize context-mode search in tgrep serve and 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

Comment thread tgrep-cli/src/serve.rs Outdated
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>
@shengyfu
Shengyu Fu (shengyfu) merged commit a32c0d9 into main Apr 22, 2026
9 of 10 checks passed
@shengyfu
Shengyu Fu (shengyfu) deleted the perf/parallel-filestamps branch April 22, 2026 22:02
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: context-mode search falls back to sequential iteration perf: collect_filestamps runs sequential I/O

3 participants