fix(code-index): delete a reindex's stale rows in one pass per FTS table - #26
Merged
Merged
Conversation
The FTS5 tables are rowid-keyed, so deleting a file's rows by file_path or symbol_id scans the whole table. Done per file, a symphony-alpha reindex cost ~2 s per changed file; the backlog after a pull outran the autosync subprocess's 600 s timeout and never committed. Also stop resolving every path component per file on each run. Co-Authored-By: lemoncrow <302591943+lemoncrow-agent[bot]@users.noreply.github.com>
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.
Problem
An incremental reindex of symphony-alpha ran for more than 10 minutes and never finished.
The FTS5 tables (
file_line_ftswith 12.4M rows,symbol_fts,symbol_trigram,file_path_trigram) are keyed by rowid only;file_pathandsymbol_idare UNINDEXED columns. So_delete_file_index, run once per changed file, did a full scan of each table for every file: about 2.2 s per file. After this morning's pulls, 556 files were stale, which is about 20 minutes of scanning.The autosync subprocess is killed at 600 s. Every run died before committing, the next run started over, and the live index had not committed in hours.
Fix
_delete_files_indexremoves a whole batch's rows with one statement per table (… IN (SELECT value FROM json_each(?))). That is one scan per FTS table per run. The regular tables are indexed on these columns, so batching costs them nothing. All three call sites use it._excludedno longer resolves each path when there are no exclude patterns (2.3 s per run)._dir_cached_relpath). Its output is identical to_safe_relpathon all 19,749 files of two real repos, and a symlink case is tested separately.Results
symphony-alpha, measured on a copy-on-write clone of the live index. The machine was under heavy load, so ranges are given.
Tests
mainit fails with "7 stale files cost 28 FTS scans".test_index_pool_does_not_fork_live_parent_state, fails onmaintoo (macOS usesspawn).Related
One of three independent fixes for code search failing on symphony-alpha:
fix/code-engine-autosync-leak,fix/incremental-reindex-batched-deletes,fix/search-reads-during-reindex. Each is based onmain, and all three merge cleanly in any order (checked withgit merge-tree, and their new tests pass together on an octopus merge).