Hasty Briefsbeta

Bilingual

Optimizing My Disk Usage Program

9 months ago
  • #macOS
  • #concurrency
  • #performance
  • The article discusses performance improvements in 'dumac', a fast disk usage program for macOS.
  • The initial version used Tokio for concurrency, but switching to Rayon improved performance by ~28% by reducing thread scheduling overhead.
  • Rayon's work-stealing design allowed for more efficient recursive directory size calculations with minimal overhead.
  • The article highlights the reduction in syscalls and context switches (~80% decrease) after switching to Rayon.
  • A sharded hash-set was used to deduplicate inodes, but inodes' sequential nature caused lock contention.
  • Optimizing the shard selection by shifting inode bits (inode >> 8) reduced lock collisions from ~176 to ~4 on average.
  • The final performance gain from reducing inode lock contention was ~5%.
  • The improvements were benchmarked and verified using hyperfine and macOS Instruments.