Optimizing My Disk Usage Program

submited by
Style Pass
2025-08-07 16:00:02

In my previous post, Maybe the Fastest Disk Usage Program on macOS, I wrote about dumac. A very fast alternative to du -sh that uses a macOS-specific syscall getattrlistbulk to be much faster than the next leading disk usage program.

I received some great technical feedback in the Lobsters thread. After implementing some of the suggestions, I was able to increase performance by ~28% on my large benchmark.

The main performance gain came from reducing thread scheduling overhead, while minor gains were from optimizing access to the inode hash-set shards.

Tokio runs many tasks on a few threads by swapping the running task at each .await. Blocking threads are spawned on demand to avoid blocking the core threads which are handling tasks. I learned this after shipping the first version when I read CPU-bound tasks and blocking code.

Spawning a new thread for each syscall is unnecessary overhead. Additionally, there aren't many opportunities to use non-blocking I/O since getattrlistbulk is blocking. Opening the file descriptor on the directory could be made async with something like AsyncFd but it's very quick and isn't the bottleneck.

Leave a Comment
Related Posts