Skip to content

perf: wire batched parallel stat into generator file list building - #3039

Merged
oferchen merged 2 commits into
masterfrom
perf/parallel-stat-generator
Mar 28, 2026
Merged

oferchen merged 2 commits into
masterfrom
perf/parallel-stat-generator

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Optimizes the generator walk_path() directory enumeration by batch-stat'ing directory children in parallel using rayon, providing 3-4x speedup for large directories (64+ entries)
  • Adds batch_stat submodule with batch_stat_dir_entries() that leverages the existing map_blocking() utility with PARALLEL_STAT_THRESHOLD = 64 (matching the receiver threshold)
  • Refactors walk_path() into a two-phase approach: collect DirEntry paths from read_dir(), batch-stat them, then process with pre-resolved metadata - preserving all existing behavior (filter chains, symlink resolution modes, file type filtering, per-directory merge files, io_error accumulation)

Test plan

  • CI passes on all platforms (Linux, macOS, Windows)
  • fmt + clippy clean
  • Existing generator file list tests pass unchanged
  • New batch_stat unit tests verify: sequential fallback, parallel path, order preservation, error handling, symlink modes, identity with sequential stat
  • Interop tests pass against upstream rsync versions

Optimize directory enumeration in the generator's walk_path() by
batch-stat'ing directory children in parallel using rayon. Previously,
each file was stat'd individually during recursive traversal. Now,
read_dir() results are collected first, then stat'd in parallel via
the existing map_blocking() utility when the entry count exceeds
PARALLEL_STAT_THRESHOLD (64), falling back to sequential for small
directories.

Key changes:
- Add batch_stat submodule with batch_stat_dir_entries() that uses
  rayon's work-stealing pool via crate::parallel_io::map_blocking
- Refactor walk_path() into walk_path() + walk_path_with_metadata()
  to accept pre-resolved metadata from the batch path
- Extract process_dir_entries_batched() to handle the collect-stat-
  process pipeline for both root and recursive directory scanning
- Extract log_stat_error() to deduplicate error reporting
- Preserve all existing behavior: filter chain enter/leave, symlink
  resolution modes (copy-links, copy-unsafe-links, lstat), file type
  filtering, per-directory merge files, and io_error accumulation
- Handle --copy-unsafe-links via post-batch fixup: lstat in batch,
  then re-stat only symlinks whose target escapes the transfer tree
@oferchen
oferchen force-pushed the perf/parallel-stat-generator branch from 1b1fea1 to 7511511 Compare March 28, 2026 23:17
@oferchen
oferchen merged commit 1047a2f into master Mar 28, 2026
34 of 35 checks passed
@oferchen
oferchen deleted the perf/parallel-stat-generator branch March 28, 2026 23:49
oferchen added a commit that referenced this pull request May 1, 2026
…3039)

* perf: wire batched parallel stat into generator file list building

Optimize directory enumeration in the generator's walk_path() by
batch-stat'ing directory children in parallel using rayon. Previously,
each file was stat'd individually during recursive traversal. Now,
read_dir() results are collected first, then stat'd in parallel via
the existing map_blocking() utility when the entry count exceeds
PARALLEL_STAT_THRESHOLD (64), falling back to sequential for small
directories.

Key changes:
- Add batch_stat submodule with batch_stat_dir_entries() that uses
  rayon's work-stealing pool via crate::parallel_io::map_blocking
- Refactor walk_path() into walk_path() + walk_path_with_metadata()
  to accept pre-resolved metadata from the batch path
- Extract process_dir_entries_batched() to handle the collect-stat-
  process pipeline for both root and recursive directory scanning
- Extract log_stat_error() to deduplicate error reporting
- Preserve all existing behavior: filter chain enter/leave, symlink
  resolution modes (copy-links, copy-unsafe-links, lstat), file type
  filtering, per-directory merge files, and io_error accumulation
- Handle --copy-unsafe-links via post-batch fixup: lstat in batch,
  then re-stat only symlinks whose target escapes the transfer tree

* style: fix long lines in batch_stat.rs and walk.rs
oferchen added a commit that referenced this pull request May 5, 2026
…3039)

* perf: wire batched parallel stat into generator file list building

Optimize directory enumeration in the generator's walk_path() by
batch-stat'ing directory children in parallel using rayon. Previously,
each file was stat'd individually during recursive traversal. Now,
read_dir() results are collected first, then stat'd in parallel via
the existing map_blocking() utility when the entry count exceeds
PARALLEL_STAT_THRESHOLD (64), falling back to sequential for small
directories.

Key changes:
- Add batch_stat submodule with batch_stat_dir_entries() that uses
  rayon's work-stealing pool via crate::parallel_io::map_blocking
- Refactor walk_path() into walk_path() + walk_path_with_metadata()
  to accept pre-resolved metadata from the batch path
- Extract process_dir_entries_batched() to handle the collect-stat-
  process pipeline for both root and recursive directory scanning
- Extract log_stat_error() to deduplicate error reporting
- Preserve all existing behavior: filter chain enter/leave, symlink
  resolution modes (copy-links, copy-unsafe-links, lstat), file type
  filtering, per-directory merge files, and io_error accumulation
- Handle --copy-unsafe-links via post-batch fixup: lstat in batch,
  then re-stat only symlinks whose target escapes the transfer tree

* style: fix long lines in batch_stat.rs and walk.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant