Skip to content

Implement persistent manifest cache and parallel file scanning - #21

Merged
guydols merged 3 commits into
mainfrom
dev
Sep 11, 2026
Merged

guydols merged 3 commits into
mainfrom
dev

Conversation

@guydols

@guydols guydols commented Sep 11, 2026

Copy link
Copy Markdown
Owner

This pull request introduces a persistent manifest hash cache to the filesync crate, significantly improving scan performance by avoiding redundant file hashing when file metadata hasn't changed. It also refactors the manifest-building logic to support pipelined, parallel directory scanning and hashing, and updates the hashing logic to use blake3's mmap and rayon features for better performance on large files.

The most important changes are:

Manifest Hash Caching and API:

  • Added a new module manifest_cache that implements a persistent, metadata-sensitive hash cache (ManifestCache) stored in .bh_filesync/manifest-cache.json, with logic for atomic saves, corruption recovery, and stability gating. This cache is used to speed up repeated scans by skipping hashing for unchanged files.
  • Updated the manifest-building logic (build_manifest in manifest.rs) to use the hash cache, track cache hits/misses, and return updated cache and scan statistics alongside the manifest.
  • Exposed cache-related types and constants in the crate root for use elsewhere. [1] [2]

Parallel and Tiered Hashing Improvements:

  • Refactored file hashing to use a tiered approach with blake3's update_mmap_rayon for large files (with streaming fallback), and pipelined directory traversal using jwalk and rayon for improved parallelism and throughput. [1] [2]
  • Updated all call sites (including the large file streaming path and conflict detection) to use the new hash_file_tiered function for consistent, efficient hashing. [1] [2] [3]

Dependency and Infrastructure Updates:

  • Added new dependencies (jwalk, num_cpus) and enabled blake3's mmap and rayon features to support the new parallel and memory-mapped hashing logic.

These changes together provide a major performance upgrade for large and repeated syncs, while maintaining correctness and robustness.

References:

Warm scans re-read and re-hashed every file on each boot. The cache in
.bh_filesync/manifest-cache.json stores size + mtime + inode per path so
unchanged files skip hashing entirely.

Trust requires size, mtime (ns precision) and inode to all match, the
file to be older than 5s (rapid rewrites always re-hash), and no pending
watcher event for the path.
Replace serial WalkDir collect-then-hash with a jwalk parallel walk
pipelined through a bounded channel into a rayon pool sized by core
count instead of the fixed 4 threads, so walking overlaps hashing.

Hashing is tiered by size: buffered streaming below 128KB, mmap for
files 4MB and up with streaming fallback, one shared helper for the
manifest, sync engine and bundler paths.
Covers cache roundtrip, hit-skip, mtime and inode invalidation, the 5s
age gate, dirty-path bypass, prune-missing, corrupt-backup handling and
the rapid-rewrite scenario.
@guydols guydols self-assigned this Sep 11, 2026
@guydols
guydols merged commit 60427f4 into main Sep 11, 2026
2 checks passed
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.

1 participant