Problem #
Measured on a live home directory cache:
top_files+ its 3 indexes consume 1,623 MiB (67% ofcache.sqlite3):top_filestable: 698.7 MiBsqlite_autoindex_top_files_1: 495.9 MiBidx_top_files_dir: 402.1 MiBidx_top_files_phys: 26.7 MiB
- Out of
2,237,735rows, 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:
DirectoryLedgerdisplays only the active directory's files (top_files.slice(0, 15)).ScatterLensonly queries the top 600 largest files.- All
directoriestotals, counts, and histograms are computed during scanning — they do not read fromtop_files.
Estimated Savings #
- ~1.55 GiB (reduces
top_files+ indexes from ~1,623 MiB down to ~50–70 MiB, or< 15 MiBwhen combined with path normalization).
Proposed Fix #
- Introduce a minimum size floor (e.g.,
>= 64 KBor>= 256 KB) for rows persisted intotop_files(or retain only the top ~50k–100k largest files globally for Scatter & Search) and lowerMAX_TOP_FILES_PER_DIRfrom32to15. - For
/api/directory?path=X, read the single inspected directory's direct files live via read-onlyfs::read_dir(sub-millisecond on APFS, shows all direct files rather than capping at 32, and falls back to cachedtop_filesif unreadable/mocked in tests). - Keep
directoriestotals, file counts, and histograms 100% exact (unchanged). - Add unit/integration tests verifying
directoriestotals remain exact when small files are excluded fromtop_files, and/api/directorystill lists small direct files in the inspected directory.