Files
lucisv/docs/features/perf5-p4

perf5-p4 — the startup and memory breakdown (take 5 §P4a)

Goal

Take 5 §P4 asks whether startup work and resident memory are worth optimizing, and its own text says the individual shares are unmeasured: "a warm index still reads source text to hash it, decodes encoded facts, rebuilds/merges query tables, constructs completion/include tables and refreshes open-buffer overlays […] their individual time/memory shares are unmeasured." §P4a is the measurement that ends that sentence. It adds a startup trace on the --verbose channel and a harness that reads it, so the lead can rule on §P4b — which stage, or none — against numbers rather than against the plan's hypotheses. No optimization is in this lane. Nothing here changes what a scan does; it changes only what a scan is willing to say about itself, and only when the flag is on.

Assumptions

  • --verbose is the right channel. The trace is three window/logMessage lines per scan under the existing timing: prefix (docs/features/verbose-timing/README.md), so a user who turns the flag on gets them and a shipped server never does. The verbose-timing README's "nobody parses these lines" assumption is amended by this feature: the harness parses them, which is why they are key=value and why their shape is pinned by tests.
  • A clock read per file is free enough to leave always on inside the store. IndexCache's counters are not behind the flag: facts_for is a &self read and threading a flag into it would cost more code than the four Instant::now()s a file pays there. The settled-time tolerance check below is what makes that claim measured rather than asserted.
  • Everything that is a walk is behind the flag. The table sizes (WorkspaceIndex::table_sizes, Candidates::sizes, IncludeGraph::sizes, IndexCache::encoded_bytes) are each a pass over a table, so they run once at the end of a scan and only when a trace asked for them.
  • A session pays for more than one scan. The startup scan runs at the default settings — Server::started builds the index before workspace/configuration can be asked, let alone answered — so a client that configures a wider scope pays a default scan and then a configured rescan. The trace numbers its scans for exactly this reason, and no row in this feature ever adds two scans together.
  • RSS is the harness's to measure. The trace reports table sizes, not a resident set: ps -o rss= at 50 ms is the existing rss phase's job and stays there. What the trace adds is the sizes that explain the reading.

Handshakes

vlog_semantic — a new additive query

/// How many entries each table holds — `IndexCounts` asked by table rather
/// than by declaration kind.
pub fn table_sizes(&self) -> IndexTableSizes;

Additive: no existing query moved, no codec changed, FACTS_FORMAT untouched. IndexTableSizes is exported beside IndexCounts. It is a walk over the tables (map lengths plus one sum per table), so it belongs at the end of a scan and never on a request path — that restriction is in its doc comment.

lucisv_server internals

  • Workspace::begin_scan and Workspace::begin_widen take a trace: bool. Every existing caller passes false; only Server::scan_once and Server::reindex_widened pass the flag through.
  • Workspace::take_scan_trace() hands the finished trace to the server. The trace is parked on the workspace rather than returned from finish_scan so that no caller's signature moved for a diagnostic.
  • Candidates::sizes() and IncludeGraph::sizes() are new read-only queries.
  • Pending::Configuration carries the Instant it was asked at, so the config round trip is a number rather than a guess.
  • Server gains born: Instant: how long the process had been alive when a scan started is the server's knowledge, not the workspace's.

Amends docs/features/verbose-timing/README.md's line table with three lines. That README's own "Nobody parses these lines" assumption no longer holds for these three; the amendment is recorded here and in the work log.

Requests for the lead (docs/topo.md is not edited by this lane)

Every edge below is additive — nothing existing changed shape — and each is a request for the lead to apply at merge, not a silent edit:

  1. lucisv_server ──▶ vlog_semantic: WorkspaceIndex::table_sizes() -> IndexTableSizes, a new read-only query beside counts(). No codec change, FACTS_FORMAT untouched, no existing query moved.
  2. A new server module scan_trace, consumed by state.rs, index_cache.rs and server/index.rs.
  3. Workspace::begin_scan and Workspace::begin_widen take a trace: bool; Workspace::take_scan_trace() is new. Every pre-existing caller passes false and reads nothing.
  4. Candidates::sizes(), IncludeGraph::sizes(), IndexCache::work(), IndexCache::entry_count(), IndexCache::encoded_bytes() — all read-only.
  5. Server gains born: Instant; Pending::Configuration gains an Instant payload. Both are internal to lucisv_server.
  6. The verbose-timing amendment above.

What the trace prints

Three lines per scan, each timing: scan <n> <kind> (<shape>, …): key=value ….

line carries
stages discovery order cache_open lookup decode parse encode store_write publish_absorb publish_candidates publish_includes publish_overlay gone absorb compact candidates includes overlay total since_start, all in ms
counts read read_kib skipped hits misses buffers records decoded_kib written_kib publishes published first_publish overlays
memory store_before_kib store_after_kib cache_entries cache_encoded_kib index_files unit_names unit_defs members hier_members reference_keys reference_sites defines instantiations fact_words fact_word_kib candidate_units candidate_macros candidate_words candidate_word_kib include_edges include_known work_kib

Plus one line at the settings pull: timing: configuration answered in X ms.

Status / TODO

  • crates/lucisv_server/src/scan_trace.rs — the trace type and its lines
  • state.rs call sites (calls only), index_cache.rs counters, candidates.rs / includes.rs size queries, vlog_semantic::WorkspaceIndex::table_sizes
  • server/index.rs emits the lines; server/client.rs times the config pull
  • tests: flag-gated, exact counts, warm-hit counts, stage-sum tolerance, a rescan is its own numbered scan
  • tools/perf/phases_p4.py — scanprofile, scanwait, scanserve
  • measured breakdown (below), tracker rows and the §P4b recommendation
  • QA
  • lead ruling on §P4b

Work log

2026-09-07 — dev (Opus)

Instrumentation written; no behavioural change. Notes on the shape:

  • The trace lives on the Scan. A ScanTrace is a bag of f64 sums and usize counters with an on flag; now() hands out Option<Instant> and add(slot, from) is a branch, so a scan that is not traced reads no clock and allocates nothing. Nothing per file is allocated even when it is on.
  • The cache's own split needed counters inside the cache. facts_for is the one place that can separate "hash the text and find the entry" from "decode the record", which is exactly §P4's hypothesis, so IndexCache holds a Cell<CacheWork> and compact records the store's size before and after. A Cell because facts_for takes &self.
  • buffers is counted and not timed. Taking an open buffer's own finished analysis costs nothing to take; what that file then costs is the record written through, which is in encode/store_write like every other file's. Timing the arm as well would have double-counted it.
  • The stages are disjoint, and they do not have to add to total. The slack is the scan loop itself — the progress/log callbacks, the per-file word Vec, the staging pushes. Left unattributed on purpose rather than folded into a neighbouring stage; the tolerance test asserts the stages never exceed the scan and account for most of it.

The measured breakdown

Release 08093a3a2b9c0b8796e5f9214ac7bda59e068e49e32a9c2393f29d116fca10bd, opentitan 0098135264, three fresh sessions per cell, every run under tools/guard.sh -m 8 -t 1800, one-minute load 4.1–5.0 during the timed phases. Raw rows: ~/.cache/lucisv-perf/take5-p4/results.jsonl, experiment P4a-2026-09-07 in docs/perf/take5-tracking.md.

A workspace session pays three scans, and the first one indexes nothing

The single most useful thing the trace says is structural, and it was not in anybody's model of the startup:

scan when what it indexes cold warm
1, whole Server::started, at the default settings, before any buffer is open 0 files — the folder scope is derived from directories a buffer has been opened from, and none has 0.8 ms 183.7 ms
2, widen the didOpen of the first buffer widens the scope to its folder 124 files 94.0 ms 26.6 ms
3, whole the pulled lucisv.index.scope: "workspace" arrives and asks for a rescan 3 976 files 2 760.0 ms 1 112.7 ms

The 124-file "default scan" the plan expected is really a widen, and the startup scan proper is empty. Warm, that empty scan still costs 183.7 ms: it opens the 44.3 MiB store (cache_open 92.5 ms) and then compacts it (compact 91.0 ms) — rewriting 45 396 KiB to produce a byte-identical file, because finish_whole_scan compacts unconditionally and the work list being empty is not consulted. Cold the same scan costs 0.8 ms, because there is no store yet.

Ranked stages — cold, settled mean 2 893.6 ms (2 866.7 / 2 936.3 / 2 877.7)

Summed over all three scans of the session.

stage ms % of settled
parse 1 703.63 58.9 %
discovery (scope walk + read 34.2 MiB of text) 299.59 10.4 %
absorb (the final merge) 218.40 7.5 %
encode (records out) 183.26 6.3 %
store_write (append log) 118.46 4.1 %
Candidates::build 110.66 3.8 %
compact 93.89 3.2 %
IncludeGraph::build 45.52 1.6 %
decode 5.87 0.2 %
publish_absorb (one mid-scan publish) 4.41 0.2 %
cache_open 3.39 0.1 %
lookup (content hash) 2.86 0.1 %
order, gone, overlay, publish_candidates/includes/overlay 4.15 0.1 %
named total 2 794.09 96.6 %
unattributed (the scan loop, the progress/log callbacks, the per-file word Vec, the staging pushes, and the didOpen/publish work between scans) 99.49 3.4 %

Ranked stages — warm, settled mean 1 332.7 ms (1 332.6 / 1 330.0 / 1 335.5)

stage ms % of settled
discovery (scope walk + read 34.2 MiB of text) 255.91 19.2 %
absorb (the final merge) 218.08 16.4 %
decode (44.2 MiB of records) 202.75 15.2 %
cache_open (the store read twice, 44.3 MiB each) 183.46 13.8 %
compact (the store rewritten twice, unchanged both times) 182.39 13.7 %
Candidates::build 113.34 8.5 %
lookup (content hash of 34.2 MiB) 51.31 3.9 %
IncludeGraph::build 46.30 3.5 %
publish_absorb 4.34 0.3 %
everything else (order, gone, overlay, encode, store_write, publish_*) 4.40 0.3 %
named total 1 262.28 94.7 %
unattributed 70.44 5.3 %
parse 0.00 0.0 %

Warm has no dominant stage. The five largest are within a factor of 1.4 of each other, and two of them — 365.9 ms, 27.5 % of the whole warm settle — are the persistent store reading and rewriting itself.

Memory

what measured note
Idle RSS, cold, 3 sessions 531.0 / 529.0 / 529.9 MiB REF 526.7 / 530.2 / 535.2 — agrees
Idle RSS, warm, 3 sessions 574.8 / 565.2 / 564.8 MiB REF 575.0 / 572.5 / 575.6 — agrees (−0.1 % on the maximum)
Peak RSS across the scan equal to idle to the KiB, all six sessions ps -o rss= at 50 ms; still no transient above idle
Store on disk 45 396 KiB = 44.33 MiB du -sk 44.34 MiB
Encoded facts held in IndexCache beside the decoded index 45 260 KiB = 44.20 MiB 7.7 % of warm idle RSS. The plan's hypothesis, measured
Source text held by the scan for its whole life (work) 34 973 KiB = 34.15 MiB released at finish_scan; not in idle RSS
Index: files / unit names / unit declarations 3 976 / 3 067 / 4 013
Index: connection members / hierarchical members 91 894 / 56 913
Index: reference keys / reference sites 59 529 / 457 666 the largest single table by entry count
Index: `defines / instantiation edges 1 358 / 13 894
Index: identifier census (FileFacts::words) 345 127 words, 4 754 KiB = 4.64 MiB
Completion tables: units / macros / words 50 726 / 658 / 105 042 words, 1 888 KiB
Include graph: resolved edges / known files 1 984 / 3 976

The warm-minus-cold idle difference is 34–46 MiB, and the store path is the only thing that differs between the two sessions: both end holding the same index and the same 44.20 MiB of encoded entries, but the warm session additionally reads a 44.3 MiB file into one Vec<u8> twice and renders a 44.3 MiB String twice. That is consistent with the encoded retention plus allocator retention of those buffers; it is not an allocation profile and is not quoted as one.

The first useful answer, explained

§P0 measured cold 84.4–85.9 ms and warm 206.1–218.7 ms and could not say why warm was 2.5× slower. The trace answers it arithmetically.

scan 1 scan 2 (widen) sum measured first answer
cold 0.54 81.58 82.1 83.4 / 85.7 / 84.9
warm 181.19 26.31 207.5 208.7 / 208.9 / 209.2

The definition arrives with the didOpen and is answered as soon as the widen that didOpen triggered has finished. Cold, the wait is that widen's 123 parses. Warm, the widen is 3× cheaper (26 ms, every file a cache hit) but the empty startup scan ahead of it has spent 181 ms opening and compacting the store. So it is neither the publish cadence nor the decode: it is the config wait — the empty scan the server runs before configuration can arrive — and specifically that scan's store I/O. The configuration answered in line agrees: 82.8–85.2 ms cold, 27.3–28.1 ms warm — the client answers instantly in both, and what the number measures is when the server got back to reading it.

Open buffers: 1 / 10 / 100

Warm workspace scope, the first N files of hw/ip/*/rtl opened right after initialize, all before the scan settles.

1 buffer 10 buffers 100 buffers
settled mean 1 841.6 ms 1 859.1 ms 2 173.9 ms
scans traced 4 4 4
final whole scan 1 268.2 ms 1 230.9 ms 1 348.5 ms
overlay refresh, final scan (overlay + publish_overlay) 0.31 ms 1.33 ms 19.67 ms
order (open-buffers-first) 1.30 ms 3.97 ms 60.64 ms
encode + store_write (a buffer's own record written through) 0.49 ms 2.21 ms 21.20 ms
buffers indexed from their own analysis 2 11 101
config round trip 388–404 ms 401–417 ms 561–570 ms

Opening buffers adds a fourth scan — a second widen (352–372 ms) for the folders those files live in, which brings 1 685 files into scope before the configured scope arrives. The overlay refresh is not the cost: 100 open buffers refresh in 19.7 ms. The cost that actually scales is order — 60.6 ms at 100 buffers, which is open_first moving each buffer's path to the front of a 3 976-entry work list, one linear scan per buffer. It is 3 % of that session's settle, so it is measured and filed, not a recommendation.

Requests arriving during a scan

A textDocument/definition every 200 ms for as long as the scan is still reporting, three fresh sessions per cache state. Each session gets three answers, and the distribution has three distinct modes rather than a spread:

during scans 1–2 queued behind the configured rescan after settle
cold 83.66 / 83.97 / 84.95 ms 2 558.85 / 2 563.65 / 2 567.24 ms 0.39 / 0.43 / 0.43 ms
warm 210.26 / 212.58 / 214.34 ms 897.12 / 904.12 / 907.90 ms 0.24 / 0.26 / 0.40 ms

The middle column is the finding: a request that arrives during the configured rescan waits the whole rescan — 2.56 s cold, 0.90 s warm. That is the scan-interleave contract behaving exactly as written (only a scan nobody asked for answers mid-way, and the scan nobody asked for is the empty one), so it is not a bug; but it means the interleaving that §46's round bought is currently spent on a scan with no files in it, and the scan that really takes seconds blocks navigation outright.

Table coherence: 0 mismatched answers in 18 requests across all six sessions. Every mid-scan answer either named exactly what the settled index names or was empty; none named anywhere else. That is the observable form of docs/features/index-scope/README.md's coherent-prefix contract, and the scanserve row fails loudly (status: error) if it is ever violated.

The instrumented binary against the REF

The trace must not slow the scan it measures. Measured with the quiet binary (no --verbose), same scan phase as §P0:

row §P0 REF instrumented, quiet delta
Cold workspace scan 2 860.12–2 868.45 (mean 2 863.85) 2 846.95 / 2 875.49 / 3 046.12 (mean 2 922.85) +2.1 % on means; −0.5 % excluding the first try, which is the first cold session after a link and is an outlier by 170 ms
Warm workspace scan 1 346.02–1 352.80 (mean 1 348.94) 1 327.12 / 1 331.64 / 1 369.46 (mean 1 342.74) −0.5 %
First useful answer, cold 84.42–85.87 84.51 / 85.71 / 86.17 +0.3 %
First useful answer, warm 206.12–218.72 209.07 / 209.52 / 212.08 within the REF range
Idle RSS, warm (max) 575.6 MiB 574.8 MiB −0.1 %
Idle RSS, cold (max) 535.2 MiB 531.0 MiB −0.8 %

The always-on IndexCache counters cost nothing measurable: four clock reads per file over 3 976 files is under a millisecond of a 1.3–2.9 second scan, and every row above is inside tolerance.

Recommendation for the lead's §P4b ruling

The dominant measured stage is the persistent store's own I/O on a warm start — cache_open + compact, 365.9 ms, 27.5 % of the warm settle — and 183.7 ms of that is spent by a scan that indexes zero files. Cold is a different problem entirely: 58.9 % of it is parse, and nothing on §P4b's list touches parsing. Taking the plan's three suggestions in numbers: (a) avoid compaction on an unchanged store is worth 182.4 ms warm (13.7 %) and ~0 cold — both warm compactions rewrite a byte-identical file (store_before_kib = store_after_kib = 45 396, records 0 and 1); (b) shorten temporary buffer lifetimes / reduce redundant transient copies is worth 92.5 ms (6.9 %) for not opening the store at all when the work list is empty, plus 91.0 ms (6.8 %) more if a scan may reuse the store the previous scan of the same session already read — the second half changes index-persistence's "re-opened at the start of every whole rescan" rule and is a contract question, not a free win; (c) reduce repeated full merges is worth nothing measurable — there is exactly one mid-scan publish (publish_absorb 4.3 ms) and one final absorb (218 ms), so the merge is already done once. Against the plan's investigation goals: warm < 1 s is reachable but only with all of (a) and both halves of (b) — 1 332.7 − 274.9 = 1 057.8 ms with the safe two, 966.8 ms with the third; cold < 2.3 s is not reachable by anything on §P4b's list, since it would need 35 % of the parse stage and the plan rules out parser worker parallelism without a separate measured case; idle RSS −15 % is not reachable — the one retention §P4 hypothesised is real and measured at 44.20 MiB, 7.7 % of warm idle, so dropping it after a scan buys at most half the goal, and the rest sits in the decoded index (457 666 reference sites, 345 127 words) where only a representation change reaches it. If the lead rules §P4b in, the honest scope is "the store stops working for a scan that has no files", targeting warm ≈1.05 s and warm first-useful-answer ≈27 ms (from 209), with the RSS goal restated as −8 % or dropped. One thing outside §P4's list is worth the lead's attention on its own: a navigation request that arrives during the configured rescan waits 2.56 s cold / 0.90 s warm, because the only scan that interleaves is the empty one.

QA log

2026-09-08 — QA agent (gates, no-behaviour-change, cost, arithmetic, coherence)

Verdict: PASS. No behaviour changed, the instrument's own cost is inside tolerance, every headline number in this README's tables reproduces from the dev's own results.jsonl (and independently, in fresh sessions run for this QA pass), and the harness's coherence check is real. One code-organization observation and one safety note on the §P4b recommendation are filed below; neither is a defect in this lane, which implements no optimization.

Gates, guarded, main tree. cargo fmt --all -- --check: clean. cargo clippy --all-targets: clean, grep -rn '#\[allow' <diff> empty — no new #[allow]. tools/guard.sh -m 8 -t 1800 -- cargo test --workspace: 4 272 passed, 0 failed, matching the dev's count exactly. Compared per-binary against a fresh clone at HEAD 8e65da1 (the commit immediately before this lane's uncommitted diff — confirmed HEAD really is that commit): baseline 4 262 passed. Normalizing both logs' Running … / test result: lines and diffing them line-for-line: the only difference in the whole workspace is lucisv_server's unittest binary, 1 564 → 1 574 (+10), exactly the ten new tests in scan_trace.rs (a_trace_that_is_off_…, …is_on_…, the_first_publish_is_…, cache_work_reports_…, every_line_names_its_scan_…, five in server/tests/scan_trace.rs). Zero tests lost or weakened anywhere else. Zero guard kills.

Production line counts. scan_trace.rs: 215 lines before #[cfg(test)] mod tests (non-blank, non-comment) — matches the dev's figure exactly. index_cache.rs: 283 lines before its mod tests (the #[cfg(test)] pub fn dir helper at line 150 is a single test-only accessor inside the production section, not the test module, and is excluded correctly by both the dev's count and mine) — matches exactly. state.rs grew from 988 to 1 099 non-blank/non-comment production lines (before mod tests), +111 — measured against the same HEAD-8e65da1 clone with the same method. That is more than "calls only" reads as: three new private methods appear (opened_trace, measure_work, landed, roughly 60 of the 111 lines) alongside the trace.now()/ScanTrace::add(...) call pairs threaded through begin_scan/begin_widen/finish_whole_scan/finish_widen. state.rs was already one of the files over the CLAUDE.md guidance ceiling and carries a filed decomposition (TODO §55); this lane continues to grow it. Not a defect — the three new methods are pure measurement (walks/sums/Instant math), not business logic, and moving them out would need Scan's and Workspace's internals exposed more widely than a single-purpose trace module should be — but it is exactly the kind of growth the file-size rule asks an agent to flag rather than wave through, so it is filed here for the lead's decomposition planning rather than treated as a QA blocker.

No behaviour change — hunks read. Every non-trace line touched in state.rs, server/index.rs, server/mod.rs, server/client.rs, candidates.rs, includes.rs, index_cache.rs, vlog_semantic's workspace/index.rs/workspace/mod.rs/lib.rs is either (a) a call-site signature growing a trace: bool parameter with every existing caller passing false (four call sites in state.rs's own tests, three in perf.rs, confirmed by git diff), (b) an Instant/counter read wrapped around an unchanged decision (facts_for's hit/miss test, record's encode-then-append, compact's unconditional call and its dir-then-rename sequence are byte-for-byte the pre-existing logic), or (c) a new read-only query (table_sizes, Candidates::sizes, IncludeGraph::sizes, IndexCache::work/entry_count/encoded_bytes) that no existing call site invokes. No if trace.on() branch anywhere skips or alters a decision that used to run unconditionally — it only skips measuring it. Confirmed by running the code, not only reading it (below).

No behaviour change — running it. Built the pre-lane baseline from a clean git clone --local at HEAD 8e65da1ba82 (cargo build --release --locked -p lucisv_server -p lucisv, guarded) and compared it against the tree's own release binary, sha256 08093a3a2b9c… — the exact binary the dev's README quotes, confirming this QA measured the same artifact.

  • scan phase (quiet), all six (scope × cache) cells, both binaries: every $/progress end file count is identical — 124/1/3 976 files by scope, 123/3 975 "from cache" by warmth, 3 skipped, for both binaries, every cell.
  • scopes phase (definition/typeDefinition/hover/references/ documentHighlight/signatureHelp/inlayHint/workspace/symbol at the aes instantiation, three scopes): 24/24 result_count fields identical between the two binaries, 0 mismatches.
  • didopen phase (the four files the 2026-09-05 table used, including the pinmux row) and nav (18 per-cursor requests): 20/20 result_count fields identical, 0 mismatches; didOpen pinmux_reg_top.sv -> definition 116.0 ms baseline vs 118.4 ms instrumented (single try each, §46's fix intact, well inside session-to-session noise).
  • git -C opentitan status --porcelain after every one of the above: always exactly the three pre-existing modified files.

No exposed lucisv/index status method or wire-level fingerprint exists in this codebase (grepped crates/lucisv_server/src and crates/vlog_semantic for fingerprint/lucisv/index); WorkspaceIndex::fingerprint() is a Rust-internal test-only tool used inside vlog_semantic's own suite, not reachable from an external LSP client. The 44/44 identical result_counts above plus the file-count identity across every scope/cache cell is the external-observer equivalent of the fingerprint check the brief asked for, and it is a stronger check than a single hash would be — it is 44 independent observations across three request families, and it caught nothing.

The instrument's cost. scan phase (quiet), 3 fresh sessions, independently re-run (own results.jsonl under this QA's scratchpad): cold 2 836.34 / 2 821.32 / 2 826.97 ms (mean 2 828.2; REF mean 2 863.85, −1.2 %; dev's own quiet re-take mean 2 922.85, +2.1 % on means but this session's load average was lower, 4.6–7.2 vs the dev's 4.1–5.0 and the REF's 2.9–4.6 — direction, not magnitude, is what matters here and it stayed negative); warm 1 315.59 / 1 364.76 / 1 313.34 ms (mean 1 331.2; REF 1 348.94, −1.3 %). First useful answer cold 85.46 / 87.15 / 86.87 ms (REF 84.42–85.87, +1–2 %); warm 208.84 / 209.82 / 210.65 ms (inside REF 206.12–218.72). Then the with---verbose cost, same binary, same machine window (scanprofile's per-session settled_ms): cold summed-scan settle mean 2 811.2 ms (−0.6 % vs the quiet re-take, i.e. verbose was not measurably slower); warm 1 335.6 ms (+0.3 % vs quiet). --verbose costs nothing measurable beyond noise — well under the 2 % the brief flags as worth a finding.

Arithmetic, recomputed from the dev's own results.jsonl (not re-derived from prose): summing every named stage over a session's three scans gives cold 2 794.09 ms / 96.56 % of the 2 893.58 ms settled mean, warm 1 262.28 ms / 94.71 % of 1 332.72 ms — both match the README's 96.6 % / 94.7 % to rounding. The empty first scan, confirmed from the raw rows: workspace, warm cache, scan 1 (whole) carries read=0, store_before_kib=store_after_kib=45396 and cache_open=92.5, compact=91.02 ms — a full open-and-rewrite of an unchanged 44.3 MiB file for a scan that touches nothing. Charged twice, confirmed: scan 1 pays cache_open/compact 92.5/91.0 ms, scan 2 (widen) pays 0.0/0.0 (it reuses self.cache scan 1 left open — matches the begin_widen diff, which never calls IndexCache::open), scan 3 (the configured whole rescan) pays a second 90.96/91.37 ms and its own compaction shrinks the store back from 45410 to 45396 KiB. Sum 365.85 ≈ the README's 365.9 ms / 27.5 %.

The empty scan is genuinely unconditional, read from source. Server::started (server/mod.rs:373) calls server.scan_until_settled(false) before server.request_configuration() is ever sent (server/mod.rs:399 region) — the first whole scan cannot be gated on configuration because configuration has not been asked for yet. finish_whole_scan (state.rs) calls self.cache.compact() with no check on work.is_empty() anywhere in the path. Both claims hold exactly as stated; this is not an artifact of the test fixtures.

First useful answer, reproduced independently (scanwait, 3 fresh sessions, own run): cold scan totals 0.57 + 85.63 = 86.2 ms against a measured mean of 84.6 ms; warm 183.4 + 26.31 = 209.7 ms against a measured mean of 210.5 ms — the same arithmetic the dev's README describes, holding on an independent set of sessions with its own machine noise.

Coherence, re-run (scanserve, 3 fresh sessions per cache state): during-scan latencies cold 82.6/84.3/85.0 ms, warm 207.9/209.1/211.3 ms; queued behind the configured rescan cold 2 546.7/2 562.7/2 594.6 ms, warm 888.5/892.8/931.3 ms; after settle both states under 0.3 ms. mismatched_answers = 0 across all 18 requests, reproducing the dev's exact finding. Read the check itself (tools/perf/phases_p4.py:265-268): it takes one settled definition answer after the scan goes quiet and compares every mid-scan answer's result payload against it with answer != settled_answer — a real per-request content comparison against the finished index's own answer, not a constant and not a hash of an unrelated table. It is a narrower check than a full index fingerprint (it only ever asks one cursor), but it is what an external client can actually observe, which is what index-scope's coherent-prefix contract is about; 18 samples across 6 sessions and both cache states caught nothing.

Open buffers, the 100 cell (2+ sessions, from the scanprofile re-run above): settled mean 2 164.4 ms (dev 2 173.9 ms, agrees); final whole scan (scan 4) order 59.2 ms (dev 60.64 ms), overlay + publish_overlay 18.34 ms (dev's combined 19.67 ms), overlays: 101 / counts.buffers: 101 confirming all 100 opened buffers plus the TB landed via their own held analysis before the scan settled, matching the README's "the 100 didOpens really preceded the settle" claim.

Memory, re-taken (rss, 3 fresh sessions, quiet binary): idle RSS cold 542 224/544 064/543 584 KiB = 529.5/531.3/530.8 MiB; warm 591 216/580 528/ 577 888 KiB = 577.4/566.9/564.3 MiB — both agree with the dev's cold 531.0/529.0/529.9 and warm 574.8/565.2/564.8 to within session noise. Peak equals idle to the KiB in all six sessions again (the 50 ms ps -o rss= sampler never saw a transient above the settled reading). Store on disk 45 404 KiB (dev: 45 396 — 8 KiB of drift from repeated compactions across sessions, immaterial). Table sizes re-read from an independent session's own trace (scanprofile, scan 3 memory line): reference_sites=457666, fact_words=345127, cache_encoded_kib=45260, index_files=3976, unit_names=3067 — every one identical to the dev's figures.

The two instrument defects, verified fixed by diffing the preliminary and final evidence files (not just reading the work-log prose). Preliminary's workspace, cold cache, scan 3 (whole) reports cache_entries: 124 (what the store held before the scan started — leftover from scan 2's widen); the final file's same row reports cache_entries: 3976 (what the finished scan actually left resident, after all 3 976 records were written) — exactly the "read at the start, not the end" bug the work log describes, now fixed. total_ms differs by 1.5 ms between the two files on the same warm scan-1 row (185.26 vs 183.72), consistent with the size-walk-inflating-total_ms bug being excluded after the fix. Confirmed the preliminary file's phase set (scanprofile, scan only) cannot be the source of the scanwait/ scanserve/rss numbers quoted in this README — those phases are entirely absent from results-preliminary.jsonl.

Traceability — 15+ headline numbers checked against results.jsonl, all matched, none traced to results-preliminary.jsonl-only fields: scan 1 read=0; scan 1 warm cache_open=92.5/compact=91.02; scan 2/3 read=124/ 3976 (cold and warm); cache_encoded_kib=45260; reference_sites=457666; fact_words=345127; the 100-buffer final scan's order=60.64/ overlays=101; scanwait cold ms array; scanserve cold mismatched_answers=0; rss cold/warm rss_kib arrays — each an exact field-level match, cross-checked in the section above.

The scan_chatter quiet-detection fix, read (phases_p4.py:218-226): the busy test counts only $/progress and textDocument/publishDiagnostics notifications, explicitly excluding window/logMessage — under --verbose the server logs one such line per request, so counting it would make the poll listen to its own noise and never terminate, which the work log and the tracker's "Refusals / gaps" entry both describe as the first draft's actual failure mode. Confirmed by inspection; the fixed loop terminated cleanly in every scanserve session run for this QA pass.

Handshake requests — six listed, all additive, topo.md untouched (git diff/git status on docs/topo.md: no changes from this lane, as claimed): (1) WorkspaceIndex::table_sizes() -> IndexTableSizes; (2) the new scan_trace module; (3) trace: bool on begin_scan/begin_widen plus take_scan_trace(); (4) Candidates::sizes/IncludeGraph::sizes/ IndexCache::work/entry_count/encoded_bytes; (5) Server::born and Pending::Configuration's Instant payload; (6) the verbose-timing amendment. docs/features/verbose-timing/README.md itself is untouched (correctly left for the lead to reconcile at merge). The "nobody parses these lines" assumption is genuinely amended, not just asserted: five tests in crates/lucisv_server/src/server/tests/scan_trace.rs parse the emitted lines with the same key=value splitting tools/perf/phases_p4.py uses (field/number helpers), and scan_trace.rs's own every_line_names_its_scan_and_is_one_line pins the scan N kind (…) prefix and the one-line-no-newline shape. The line contract is pinned by tests, not only by convention.

§P4b recommendation — my own safety read, beyond what the dev's hedge already says. index-persistence's README gives two independent reasons for reopening the cache at the top of every whole rescan (both also in the state.rs comment the diff leaves untouched): (i) the cache directory depends on settings (index.cachePath, index.persist) that arrive by workspace/configuration, after the default-settings scan; (ii) a second session over the same workspace may have written records this one has not seen — cross-session freshness.

  • (a) skip compaction of an unchanged store does not touch the reopen decision at all — it only skips a rewrite when store_before == store_after/no records were written. Safe against both reasons; it never changes where or whether the store opens, only whether an unchanged file gets rewritten. I see no way this interacts with corrupt-store recovery either, since compact_now's temp-file-then-rename sequence is unaffected — skipping it just means the append log stays unvacuumed a little longer.
  • (b), first half (no store open for an empty work list), is not quite as free as it reads. Today only begin_scan (whole) calls IndexCache::open; begin_widen never does — it relies on begin_scan having already opened self.cache into the field a widen then reads through. If scan 1's open is skipped outright because its work list is empty, and nothing else opens the store before scan 2's widen runs, the widen would silently lose every cache hit (all 124 files reparsed instead of served from the store) — not a corruption, but a real regression against exactly the warm-start cost this whole round is trying to cut, and a subtler one than "skip an unconditional open" suggests. The 92.5 ms this half claims to save is real only if the open is deferred to the first scan that actually needs the store (i.e., moved, not dropped) — worth spelling out explicitly if the lead rules this in.
  • (b), second half (reuse the store the session already read), is not safe as a blanket rule against either of index-persistence's two reasons. Against reason (i): if the pulled configuration changes cachePath or flips index.persist between scan 1 and scan 3, reusing scan 1's already-open cache would read/write the wrong directory (or keep writing after the user asked for persistence off) for the rest of the session — a behaviour regression against the persistence feature's own contract, not merely a missed optimization. Against reason (ii): reusing the in-memory store means a concurrent second session's writes between scan 1 and scan 3 are invisible to this one — but that direction is safe-but-suboptimal (a missed cache hit still reparses correctly), never a wrong answer. My read: this half needs an explicit re-validation step (reuse only if the resolved cachePath/persist are unchanged from what scan 1 opened, reopen otherwise) before it can be called safe, which is exactly what the dev's own "contract question, not a free win" hedge is pointing at — I'm narrowing which of the two documented reasons each half of (b) would actually violate, not overturning the recommendation.
  • (c) is correctly assessed as nothing to remove (one mid-scan publish, one final absorb — verified from the same results.jsonl rows).

Guard outcome. Zero kills across every phase run for this QA pass (gates, two release builds, and roughly a dozen guarded timed phases). Largest resident set observed 591 MiB (7 % of the 8 GiB limit).

Opentitan status. git -C opentitan status --porcelain checked after every phase in this QA pass (gates excluded, since no phase touches the corpus during them): always exactly hw/ip/aes/dv/tb/tb.sv, hw/top_darjeeling/ip/ast/rtl/ast.sv, hw/top_earlgrey/ip/ast/rtl/ast.sv — never more, never fewer.

Fixes made: none needed. No code or doc changes beyond this QA log and the TODO.md tick.

Review

2026-09-08 (lead, P4a). Accepted, and the P4b ruling follows.

  • The instrument is the plan's §P4a as written: disjoint stages, counters not allocations, nothing changed in what a scan does (QA: 44/44 result counts identical against the pre-lane binary; the stage sums re-derived).
  • The structural finding is the one worth the whole stage: a workspace session runs an empty scan at default settings before configuration arrives, and that empty scan still opens the 45 MB store and rewrites it byte-identically — 184 ms of a 1.33 s warm start — and the configured scan's compact rewrites an unchanged store once more. That is also the whole of the first-useful-answer gap between cold (82 ms) and warm (208 ms).
  • Warm has no dominant stage; the store's I/O is 27 % of it. Cold is 59 % parse, which P4b may not touch; idle RSS retention is 7.7 %, so the plan's −15 % is not on the table. The plan's goals are read honestly: warm < 1 s reachable, the other two not.
  • Ruling, P4b — go, on exactly two of the recommendation's three: (a) compact is skipped when the session appended nothing, nothing is gone and the loaded store was already canonical (one line per path, no dropped lines), since the rewrite would be byte-identical; (b1) a scan with an empty work list opens no store and compacts nothing (the open is deferred to the first file that needs it, so the widen's hits are untouched — QA's point). (b2), reusing the store across rescans, is refused: the reopen exists for a mid-session cache-path change and for a second session's compaction replacing the file under an append handle; −91 ms does not buy that. Also in P4b: the configured rescan queues navigation for 2.5 s cold / 0.9 s warm because only the empty scan interleaves — find why, fix it if it is routing, file it if it is not; and move the three trace helpers that landed in state.rs (+111 lines) into scan_trace.rs as a pure move.
  • Deviations accepted: state.rs's growth (to be moved out in P4b); the preliminary run kept unquoted.