fix(colgrep): eliminate unnecessary re-indexing on every search (integrates #134)#137
Merged
Merged
Conversation
Integrates #134 (by @vlasky) — which fixes several issues that made every search re-hash every tracked file on large projects — with corrections. From #134 (kept): - Skip redundant canonicalize() in scan_files for paths without '..' (the walker's follow_links(false) + is_file() filter already block symlink escape). - Migrate index format 0 -> 1 in place (stat to backfill sizes, upgrade legacy second-precision mtimes to nanoseconds) instead of discarding and re-embedding the whole index — the on-disk layout did not change across 1.5.4 -> 1.5.5. - Refresh file stats after worktree seeding so git-checkout's 'now' mtimes don't defeat the fast path on first search. Corrections: - Drop the size==0 'mtime-only' fast-path tolerance: it reopened the same-second edit blind spot. Require a strict mtime+size match; legacy size==0 entries are hashed once (correct) and then backfilled by the migration / touched-persist. - Stop purging stat-missing entries from state during migration; leave them so the normal incremental-delete path removes them from every store (vector + metadata + FTS5) deterministically, instead of relying on periodic orphan cleanup. Tests: - test_index_stays_synced_with_disk: deleting files on disk is detected, purges them from every store (not keyword-retrievable), keeps survivors, and a content change is detected as changed. - test_format_migration_in_place_cleans_deleted_without_rebuild: migration reuses the legacy index (no model => a rebuild would fail) and ends in sync with disk. Validated: clippy clean; cargo test -p colgrep (557 passed). Co-authored-by: Raphael Sourty <raphael.sourty@lighton.ai> Co-authored-by: vlasky <vlad.lasky@energyone.com>
raphaelsty
added a commit
that referenced
this pull request
Jun 17, 2026
Integrates #134 (by @vlasky) — which fixes several issues that made every search re-hash every tracked file on large projects — with corrections. From #134 (kept): - Skip redundant canonicalize() in scan_files for paths without '..' (the walker's follow_links(false) + is_file() filter already block symlink escape). - Migrate index format 0 -> 1 in place (stat to backfill sizes, upgrade legacy second-precision mtimes to nanoseconds) instead of discarding and re-embedding the whole index — the on-disk layout did not change across 1.5.4 -> 1.5.5. - Refresh file stats after worktree seeding so git-checkout's 'now' mtimes don't defeat the fast path on first search. Corrections: - Drop the size==0 'mtime-only' fast-path tolerance: it reopened the same-second edit blind spot. Require a strict mtime+size match; legacy size==0 entries are hashed once (correct) and then backfilled by the migration / touched-persist. - Stop purging stat-missing entries from state during migration; leave them so the normal incremental-delete path removes them from every store (vector + metadata + FTS5) deterministically, instead of relying on periodic orphan cleanup. Tests: - test_index_stays_synced_with_disk: deleting files on disk is detected, purges them from every store (not keyword-retrievable), keeps survivors, and a content change is detected as changed. - test_format_migration_in_place_cleans_deleted_without_rebuild: migration reuses the legacy index (no model => a rebuild would fail) and ends in sync with disk. Validated: clippy clean; cargo test -p colgrep (557 passed). Co-authored-by: Raphael Sourty <raphael.sourty@lighton.ai> Co-authored-by: Vlad Lasky <12727610+vlasky@users.noreply.github.com>
This was referenced Jun 17, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Integrates #134 (by @vlasky) — which eliminates the unnecessary re-indexing that made every search re-hash every tracked file on large projects — with two correctness fixes and dedicated tests. Targets
main.From #134 (kept)
canonicalize()inscan_filesfor paths without... The walker usesfollow_links(false)and filters onentry.file_type().is_file(), so a symlink can't escape the root or even reach this check — the per-filerealpathwas dead weight.0 → 1in place (stat to backfillsize, upgrade legacy second-precision mtimes to nanoseconds) instead of discarding the index and re-embedding everything. The on-disk layout did not change across 1.5.4→1.5.5, so the rebuild was pure waste (minutes on large repos).git checkout's "now" mtimes don't defeat the fast path on a new worktree's first search.Corrections to #134
size == 0"mtime-only" fast-path tolerance. It reopened the same-second-edit blind spot (an edit landing in the same instant that the size guard was added to catch). The fast path now requires a strict mtime and size match; legacysize==0entries are hashed once (correct) and then backfilled by the migration /touched-persist.Tests (new)
test_index_stays_synced_with_disk— the core invariant: a file deleted on disk is detected by the update plan, purged from every store (no longer keyword-retrievable), survivors remain, and a content change is detected as changed.test_format_migration_in_place_cleans_deleted_without_rebuild— proves the migration reuses the legacy index (no model in the test ⇒ a full rebuild would fail to embed) and ends in sync with disk.Validation
cargo clippy -p colgrep --all-targets— cleancargo test -p colgrep— 557 passedCo-authored with @vlasky (#134).