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

Eliminate multi-GB SQLite WAL bloat and freelist fragmentation on full scans #1

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

Problem #

Measured on a live home directory scan (423,487 directories, 2,237,735 top_files rows):

  • ~/Library/Caches/getael/cache.sqlite3: 2.7 GiB (incl. 333 MiB of unused freelist pages with auto_vacuum = 0)
  • ~/Library/Caches/getael/cache.sqlite3-wal: 2.7 GiB (an entire second copy of the database sitting un-truncated on disk)

CacheStore::replace_full_scan (src/cache/mod.rs:400-460) runs DELETE FROM top_files; DELETE FROM directories; and re-inserts all rows inside a single WAL transaction without ever running PRAGMA wal_checkpoint(TRUNCATE) or bounding WAL size via PRAGMA journal_size_limit.

Estimated Savings #

  • ~3.0 GiB immediately (~2.7 GiB -wal + ~333 MiB freelist).

Proposed Fix #

  1. Set PRAGMA journal_size_limit = 33554432; (32 MiB) and PRAGMA auto_vacuum = INCREMENTAL; during schema initialization (src/cache/mod.rs:266-330).
  2. Run PRAGMA wal_checkpoint(TRUNCATE); and PRAGMA incremental_vacuum; after replace_full_scan commits.
  3. Even better: for full scans, bulk-load into a fresh sibling file (cache.sqlite3.new with PRAGMA journal_mode = OFF during insert, then switch to WAL), atomically replace cache.sqlite3, and reopen write_conn/read_conn — yielding a zero-fragmentation DB and ~0 B WAL after every full scan.
  4. Add a regression test verifying that after replace_full_scan, -wal size is truncated and freelist pages are reclaimed.
Sign up or Sign in to add to the discussion.