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
directoriestable):direct_categories_json+subtree_categories_json+ logical equivalents: 211.0 MiBdirect_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) wheresubtree_*histograms are 100% identical todirect_*.
Estimated Savings #
- ~340 MiB (reduces histogram storage from 366.6 MiB down to ~20 MiB).
Proposed Fix #
- Replace the 8 JSON text columns in
directories(src/cache/mod.rs:279-304) with compact LEB128 varint binaryBLOBs (or sparse(tag, varint)packed blobs), storingNULLwhen all buckets are zero. - For leaf directories (
direct_dir_count == 0), storeNULLfor thesubtree_*histogram columns and fall back todirect_*on read — immediately halving histogram storage for 66% of rows. - Handle schema upgrade cleanly via
schema_versionbump (rebuilding the disposable cache table on open when version changes). - Add round-trip encode/decode unit tests (including proptest) covering zero, sparse, dense, and
u64::MAXhistogram values.