Back to Publications

Measure Twice, Cut Once: the Best* Way to Calculate macOS File Hierarchy Size

    Paper
  • Software Engineering

Efficient scanning and sizing of files and directories in the Apple File System (APFS) is critical for effective storage management and system monitoring.

This study investigates algorithms for measuring the size of APFS file hierarchies with a focus on speed, scalability, and resource efficiency. The proposed solution integrates three APFS access methods—NSFileManager, URLResourceKey, and the UNIX utility du—with four traversal strategies and three multithreading approaches (serial processing, Grand Central Dispatch, and Swift concurrency).

Experimental results on synthetic hierarchies show that URLResourceKey achieves scan times an order of magnitude shorter than NSFileManager and consistently outperforms du. Furthermore, multithreaded processing with Swift concurrency or GCD reduces execution time by 2–3× compared to serial methods. The use of traversal algorithms further improves scanning performance, enhances user experience, and enables tailored optimization for specific tasks.

@unpublished{levchenko-etal-2025-report-macos-dirsize,
  author = {Artem Levchenko and Oleksandr Frankiv and Yevhenii Peteliev},
  title  = {Measure Twice, Cut Once: the Best* Way to Calculate macOS File Hierarchy Size},
  note   = {\emph{Preprint.} \url{https://research.macpaw.com/publications/disco}},
  month  = {May},
  year   = {2025}
}

Related publications