mirror of
https://github.com/tobi/disktree.git
synced 2026-11-28 08:00:53 +00:00
On macOS the walk listed each directory with std::fs::read_dir and then called DirEntry::metadata for every file, an lstat of its full path, plus one more per directory for the dataless flag and the device. On a home directory of 2.6 million directories and 17 million files that is some 20 million system calls on top of the listing, each of which makes the kernel set up per-file state. macos.rs lists a directory with getattrlistbulk(2), which returns the name, type, device, inode, modification time, flags, link count and sizes of a whole buffer of entries per call, the way windows.rs already does with FileIdExtdDirectoryInfo. The sizes are the ones stat reports: ATTR_FILE_ALLOCSIZE is st_blocks * 512 (every fork, as st_blocks counts), ATTR_FILE_DATALENGTH is st_size (the data fork). Checked against lstat on 151,000 files across system apps, app bundles, ~/Library and source trees, and by a test with sparse, hardlinked, symlinked and resource-forked files. An entry a file system describes only in part is read with statat relative to the open directory. Measured on an M5 Pro with 15 walk threads, warm and otherwise idle, alternating with upstream/main: ~/src (88k directories, 696k files) 4.3-4.5 s -> 2.0 s whole home directory (2.6M, 17M) 116.6 s -> 90.4-91.6 s User CPU for the home scan fell from 24.6 s to 9.6 s, and system CPU from 630 s to 430 s. Trees are identical to the standard listing's with hardlink de-duplication off (3.3 million nodes, both size modes); with it on the totals are identical, and which name of a hardlinked file is charged varies as it already did between runs. Linux keeps the standard listing, whose DirEntry::metadata is already a statx relative to the directory; Windows keeps its own.