dust is a very fast implementation of du in Rust.

How it’s implemented?

Concurrency

Rayon is used for parallelism.

dur_walker
use rayon::iter::ParallelBridge;
use rayon::prelude::ParallelIterator;
let children = if dir.is_dir() {
        let read_dir = fs::read_dir(&dir);
        match read_dir {
            Ok(entries) => {
                entries
                    .into_iter()
                    .par_bridge()
                    .filter_map(|entry| {
                        match entry {
	...

Get File Metadata

  • get_metadata function supports apparent size Apparent size is obtained from metadata.len(), the other option is computed with metadata.blocks() * block_size.

Avoid Double Count

Links could result in circular recursive search. inode is used to prevent this. clean_inodes called recursively on a node tree to remove existing children, identified by inodes.