Getǣl — Read-only macOS home directory disk usage cartography & APFS telemetry service

Filter tiny files out of `top_files` cache and read single-directory file lists live #2

Closed zip.mu.social
Closed opened by zip.mu.social

Problem #

Measured on a live home directory cache:

  • top_files + its 3 indexes consume 1,623 MiB (67% of cache.sqlite3):
    • top_files table: 698.7 MiB
    • sqlite_autoindex_top_files_1: 495.9 MiB
    • idx_top_files_dir: 402.1 MiB
    • idx_top_files_phys: 26.7 MiB
  • Out of 2,237,735 rows, 2,137,641 rows (95.5%) are < 64 KB.

Because MAX_TOP_FILES_PER_DIR = 32 (src/scanner/mod.rs:21) stores up to 32 files per directory across all ~423k directories (including .git, node_modules, target, and caches), millions of tiny files are persisted even though:

  • DirectoryLedger displays only the active directory's files (top_files.slice(0, 15)).
  • ScatterLens only queries the top 600 largest files.
  • All directories totals, counts, and histograms are computed during scanning — they do not read from top_files.

Estimated Savings #

  • ~1.55 GiB (reduces top_files + indexes from ~1,623 MiB down to ~50–70 MiB, or < 15 MiB when combined with path normalization).

Proposed Fix #

  1. Introduce a minimum size floor (e.g., >= 64 KB or >= 256 KB) for rows persisted into top_files (or retain only the top ~50k–100k largest files globally for Scatter & Search) and lower MAX_TOP_FILES_PER_DIR from 32 to 15.
  2. For /api/directory?path=X, read the single inspected directory's direct files live via read-only fs::read_dir (sub-millisecond on APFS, shows all direct files rather than capping at 32, and falls back to cached top_files if unreadable/mocked in tests).
  3. Keep directories totals, file counts, and histograms 100% exact (unchanged).
  4. Add unit/integration tests verifying directories totals remain exact when small files are excluded from top_files, and /api/directory still lists small direct files in the inspected directory.
Sign up or Sign in to add to the discussion.