Module bulk_stat

Module bulk_stat 

Source
Expand description

Bulk directory enumeration + metadata fetch in a single syscall.

§Why

Standard fs::read_dir returns just names + d_type. To get size/mtime we call fs::metadata() per file — one stat(2) syscall each. On SMB/NFS every syscall = network roundtrip (1-10ms LAN, 50-200ms WAN). Walking a 100k-file share spends 200+ seconds in per-file stats.

macOS has getattrlistbulk(2) which returns metadata for an entire directory in one syscall. find(1) and fts(3) use it. For SMB it’s a 10-100× speedup on metadata cost.

Other platforms (Linux, Windows) fall back to readdir+metadata. Linux has no direct equivalent — the closest is statx which is still per-file.

§Usage

Call read_dir_bulk(path) instead of fs::read_dir(path) when you need type + size + mtime per entry. Returns a Vec<BulkEntry> with all metadata already populated. If the platform-specific fast path fails (unsupported filesystem, permission error, etc.) it falls back to the portable fs::read_dir + metadata path transparently.

Modules§

macos 🔒
macOS-specific bulk metadata via getattrlistbulk(2).

Structs§

BulkEntry

Functions§

read_dir_bulk
Enumerate dir returning name + type + size + mtime for every entry in a single syscall where possible. Hidden . and .. entries are excluded.
read_dir_bulk_portable 🔒
Portable fallback: readdir + per-entry metadata. One syscall per entry.