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

Encode `directories` category and age histograms as compact binary BLOBs with leaf deduplication #3

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

Problem #

Measured across 423,487 rows in directories (562.7 MiB table data):

  • The 8 JSON histogram columns consume 366.6 MiB (65% of the directories table):
    • direct_categories_json + subtree_categories_json + logical equivalents: 211.0 MiB
    • direct_age_buckets_json + subtree_age_buckets_json + logical equivalents: 155.6 MiB
  • Every row repeats full JSON key names ("code_builds":0,"media_video":0,...) 8 times (~900 bytes/row even for empty or 1-file directories).
  • 279,292 of 423,487 directories (66%) are leaf directories (direct_dir_count = 0) where subtree_* histograms are 100% identical to direct_*.

Estimated Savings #

  • ~340 MiB (reduces histogram storage from 366.6 MiB down to ~20 MiB).

Proposed Fix #

  1. Replace the 8 JSON text columns in directories (src/cache/mod.rs:279-304) with compact LEB128 varint binary BLOBs (or sparse (tag, varint) packed blobs), storing NULL when all buckets are zero.
  2. For leaf directories (direct_dir_count == 0), store NULL for the subtree_* histogram columns and fall back to direct_* on read — immediately halving histogram storage for 66% of rows.
  3. Handle schema upgrade cleanly via schema_version bump (rebuilding the disposable cache table on open when version changes).
  4. Add round-trip encode/decode unit tests (including proptest) covering zero, sparse, dense, and u64::MAX histogram values.
Sign up or Sign in to add to the discussion.