Perf: cache word_count in manifest — detect_incremental re-parses every PDF/docx on each run
Version: graphifyy 0.9.5, corpus of ~800 files (many PDF/docx).
Problem
detect_incremental calls the full detect(), which re-parses all PDFs/docx just to count_words (detect.py:645) on every invocation — ~3 minutes on our corpus when only 5 files actually changed. The expensive part isn't hashing, it's re-opening every Office/PDF binary for a word count that hasn't changed.
Proposal
Store word_count in the manifest entry and recount only files whose hash changed. Turns incremental detection from O(corpus) parsing into O(changed).
Fixed in f917494 (on v8, ships in 0.9.7). Thanks for the measurement (~3 min on 800 files) — that made the cost obvious.
Rather than add word_count to the manifest (which would ripple through save_manifest and the generated skill files), I memoized counts in the existing content-hash stat index that file_hash already maintains — keyed by the same (size, mtime_ns) signature. So an unchanged PDF/docx is parsed once and served from the index thereafter, turning incremental detection from O(corpus) parsing into O(changed), exactly as you proposed. The two index writers (hash and word-count) now augment a shared entry in place, and file_hash's fastpath is guarded against a word-count-only entry.