Persistent index cache: a half-indexed workarea resumes where it stopped
Owner-requested round. Every parsed file's FileFacts record is written through to an index-cache store (append per file, atomic compaction at scan end — a crash loses at most the file in flight), keyed by a content hash that is the whole key: no mtime fast path, by measured argument (6 ms of a 181 ms warm scan, and unsound against save-time write-through). On reopen, hits skip parsing and the resume is visible — cached: vs indexing: log lines, the bar counting through hits, and an end message saying how many came from cache. Warm rescan 322 to 179 ms release, 1.5 s to 0.76 s debug; 910 KB store for the 860-file corpus. Location: lucisv.index.cachePath > the extension's context.storageUri via initializationOptions (the one extension.js change) > the OS cache dir keyed by workspace identity > nowhere; lucisv.index.persist (default on) gates both directions immediately. The cache is a performance artifact, never a correctness input, and after the fix round that promise is total against everything but intentional forgery — which the threat model now formally excludes (same-user disk; a keyed MAC would be theater): a per-record checksum drops every corrupt-but-parseable line (poisoned and reforged shapes both pinned so the checksum is never mistaken for a MAC), first-writer initialization is a create_new claim with structural 100/100 survival, and a torn multi-byte tail costs exactly the torn record (0 of 583 offsets lose more). Old-format stores discard wholesale. Load==fresh fingerprint equality swept over the corpus. 45 tests added across the main and fix rounds (dev 33+2, QA 9+3, one QA test-construction bug self-caught), 2 ignored probes. docs/features/index-persistence/README.md Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
5e4aa7bd6f
commit
e4b1f55c12
17 files changed
+4280
-50
No files matched your search
@@ -52,7 +52,10 @@ lookups — 92 ms → 0.26 ms for a whole file's code lenses, 82 ms → 0.71 ms
|
||||
- **The index keeps every file's contribution unmerged.** `FileFacts` — the
|
||||
path, the define table, the file-scope declarations, the members, the
|
||||
instantiation edges and the inheritance edges — used to live only until
|
||||
`IndexBuilder::finish` and now lives in the index. That is what makes the
|
||||
`IndexBuilder::finish` and now lives in the index. (**Since
|
||||
index-persistence, 2026-08-27** it also lives on *disk*: `FileFacts` is
|
||||
public, encodable and decodable, and a record put back through
|
||||
`IndexBuilder::add_facts` gives the index the file's parse would have.) That is what makes the
|
||||
restricted re-merge possible, and it is the round's honest memory cost: the
|
||||
same names and spans the merged tables hold, held once more, per file. No
|
||||
`Semantics` and no source text is retained, exactly as before.
|
||||
@@ -169,6 +172,11 @@ pub struct InheritanceEdge { pub file: FileId, pub subclass: DeclSite }
|
||||
It patches all four pieces of state a rebuild produces (index, completion
|
||||
tables, include graph, every open buffer's overlay) and is documented
|
||||
piece by piece at the function.
|
||||
**Amended (index-persistence, 2026-08-27):** it also writes the file's new
|
||||
record through to the on-disk index cache, using
|
||||
`WorkspaceIndex::facts_for` to take back the record the update just made
|
||||
rather than parsing anything twice. An hour of saves is an hour of work the
|
||||
next session does not repeat.
|
||||
- `Workspace::update_one_checked` is the `#[cfg(test)]` paranoid form: it runs
|
||||
the update, then rebuilds the whole workspace and asserts the two agree on
|
||||
the index's fingerprint *and* on the completion word table.
|
||||
@@ -223,6 +231,7 @@ the remaining rows.
|
||||
| `IncludeGraph::edges` | this file's `` `include``s | re-scanned for this file; other files' left standing (see Assumptions) |
|
||||
| `IncludeGraph::known` / `folded` | the file set | re-learned from `index.files()` |
|
||||
| every open buffer's `ExternalResolutions` | the index | refreshed, as after a rebuild |
|
||||
| the persistent index cache | this file's new record | written through, from the record `update_file` just made — no second parse (`docs/features/index-persistence/README.md`, 2026-08-27) |
|
||||
| the diagnostics generation | — | bumped |
|
||||
| the client's code lenses | the index | refresh requested |
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -166,6 +166,11 @@ pub fn build<'a>(files: …) -> WorkspaceIndex {
|
||||
- `pub enum IndexEvent<'a> { Parsing { done, total, path }, Skipped { path,
|
||||
size, cap } }`. Numbers and paths only: this module speaks no protocol, and
|
||||
the wording of every message stays in `server.rs`.
|
||||
**Amended (index-persistence, 2026-08-27):** a third variant, `Cached {
|
||||
done, total, path }` — the same three numbers, for a file the persistent
|
||||
index cache answered for instead of a parse. A new variant rather than a
|
||||
flag on `Parsing`, so that every consumer is asked by the compiler what it
|
||||
wants to say about a file that was not parsed.
|
||||
- `ClientSettings::max_file_size` is read in `collect_sources`; nothing else
|
||||
in `state.rs` changed.
|
||||
|
||||
@@ -195,6 +200,14 @@ pub fn build<'a>(files: …) -> WorkspaceIndex {
|
||||
callers, no duplicated send.
|
||||
- `end_indexing` takes the skip count and says `"N files indexed, M skipped"`
|
||||
when it is non-zero.
|
||||
**Amended (index-persistence, 2026-08-27):** it takes the *cached* count as
|
||||
well and names it first — `"860 files indexed, 858 from cache, 2 skipped"` —
|
||||
because a scan that finished suspiciously fast should say why. Same rule as
|
||||
the skip count: the number is in the end message whether or not the per-file
|
||||
log is on. `IndexWatch` also grows an arm for `IndexEvent::Cached`, whose log
|
||||
line reads `cached: <path>` where a parsed file's reads `indexing: <path>`,
|
||||
and whose bar tick is identical — a cached file is a file of the work list,
|
||||
and the bar flying through them is the point.
|
||||
- `begin` still carries **no** percentage: the first honest one is the first
|
||||
file's.
|
||||
|
||||
|
||||
@@ -236,6 +236,7 @@ reasoning and the measurements: `docs/features/cancel-request/README.md`.
|
||||
| a document's `Semantics` + tokens + diagnostics | every `didOpen`/`didChange` — **once per notification**, however many ranges it carried | one file, full recompute |
|
||||
| the `WorkspaceIndex` | `initialize`, every `didSave`, every `textDocument/didOpen` that **widens the scope**, every `workspace/didChangeWatchedFiles`, every `workspace/didChangeWorkspaceFolders` that moves the root set, and a changed `lucisv.exclude`/`lucisv.filelist`/`lucisv.index.maxFileSize`/`lucisv.index.scope`/`lucisv.index.scopeDepth` (pushed **or** pulled) | full re-scan of the scope — **except when the trigger names exactly one file the index already holds** (a `didSave`, a one-file watcher event), where only that file's contribution is replaced and the result is provably the index a full re-scan would have given (`docs/features/incremental-index/README.md`) |
|
||||
| the `` `include`` graph | with the `WorkspaceIndex`, from the same file list | a line scan per file (~6ms over the 860-file corpus). An open buffer's *own* includes are re-resolved on every request instead, so a line just typed is clickable before the next save |
|
||||
| the **index cache** on disk | appended to as a whole rescan parses each file, rewritten when that rescan ends, and written through by every incremental one-file update | one `write` per parsed file. It is read at the start of every whole rescan and answers for every file whose content it already holds, which is what makes a reopened workspace cost the reads and not the parses (`docs/features/index-persistence/README.md`) |
|
||||
|
||||
**Per-file recompute on every keystroke** is the strategy TODO.md §6 states
|
||||
("per-file recompute is fine at Verilog file sizes"); salsa is explicitly
|
||||
@@ -275,6 +276,25 @@ also fed to the index builder **first**, so a long rescan's progress bar
|
||||
completes them before anything else; the builder sorts by path internally, so
|
||||
that ordering cannot change the index it produces.
|
||||
|
||||
**What a scan learned survives the session, since 2026-08-27**
|
||||
(index-persistence). Every file a scan parses is written to a store — its
|
||||
`FileFacts`, the whole of its contribution to the index, under the FNV-1a hash
|
||||
of the bytes it was read from — and the next scan takes back every record
|
||||
whose file still holds exactly those bytes instead of parsing it again. So
|
||||
reopening a workspace, or reopening one whose first scan was interrupted, is a
|
||||
rescan that costs the reads and not the parses: **181 ms warm against the
|
||||
328 ms it cost cold** over the 860-file corpus in a release build, with the bar
|
||||
saying `860 files indexed, 860 from cache` and the output log saying `cached:`
|
||||
where it says `indexing:`. The store lives in
|
||||
`initializationOptions.storagePath` (VS Code's per-workspace storage folder),
|
||||
or wherever `lucisv.index.cachePath` says, or in this platform's cache
|
||||
directory; `lucisv.index.persist: false` turns it off in both directions and
|
||||
restores the pre-2026-08-27 behaviour exactly. **It is a performance artifact
|
||||
and never a correctness input**: every record is verified against the file's
|
||||
current content before it is used, and a stale, corrupt or foreign record
|
||||
costs one parse and can change no answer. Rules, the record format and the
|
||||
crash-safety argument: `docs/features/index-persistence/README.md`.
|
||||
|
||||
**Walked files over `lucisv.index.maxFileSize` (1 MiB by default) are not read
|
||||
at all** — the size is taken from `fs::metadata` before the read, so a
|
||||
generated netlist costs one `stat` rather than minutes of parsing. The cap is
|
||||
@@ -294,7 +314,8 @@ which the override above keeps current. Rebuilding on every keystroke would
|
||||
re-parse the whole workspace per character; rebuilding on save is the cheapest
|
||||
point where the answer is expected to change anyway. Measured cost of a
|
||||
rebuild: 0.68 s for the 860-file corpus (the workspace index's own baseline),
|
||||
plus the file reads.
|
||||
plus the file reads — **and about half that when the persistent index cache
|
||||
answers for the files that have not changed** (index-persistence, below).
|
||||
|
||||
**Every *whole* rescan is visible since 2026-08-26**, for a client that
|
||||
advertised `window.workDoneProgress`: the startup build and every whole
|
||||
|
||||
Reference in new issue
Block a user