Files
lucisv/docs/features/perf5-p2/README.md
T

41 KiB
Raw Blame History

perf5-p2 — rename reuses its analysis, verification untouched

Take 5 §P2 (docs/performance_take5.md), TODO §60.2. Stages P2a → P2b → P2c. P2d (source-set narrowing) and topology handshake 33 are not this lane's; no source set is narrowed or shared here.

Goal

A hierarchical rename on OpenTitan costs about 780 ms and nobody could say which stage that is. This lane first measures it (P2a: an additive trace carrying per-stage wall time and per-stage whole-file parse counts), then removes the repeated work the measurement names — the same file parsed and analysed two, three, four times inside one request — without touching a single one of the verifier's checks. P2b makes the request-local scope parse and analyse each file once and keep what later stages need; P2c builds the after-edit index from the unchanged files' existing facts plus the edited files' one new analysis, and re-resolves the untouched watched files against it rather than re-analysing them.

What the user sees must not move at all: the same edits, the same warnings, the same refusal sentences, the same fingerprints. A faster partial edit is a failure, and so is a faster refusal that refuses something else.

Assumptions

  • A rename is answered on one thread. vlog_parser::stats::parses() is thread-local, so a stage's parse delta is that stage's own work. This is §P1's assumption too, and the server is single-threaded per request.
  • FileFacts::of(path, src) and the Semantics its own read-off was made from describe the same text. P2b keeps that Semantics instead of dropping it; it does not recompute it, so the two cannot disagree. The additive FileFacts::analyzed is literally facts_of's body with the analysis handed back rather than dropped.
  • parse_source_tolerant(src).0 and parse_and_collect(src).0 are the same tree. parse_source_tolerant is tokenize + parse_tolerant, with parser::error_file on a lex failure; parse_and_collect is the same two branches. So the Semantics a scope retains is the one Scope::analysis used to compute for itself.
  • Retention is a cache, never an oracle. A file whose analysis was not retained is analysed on demand exactly as before, so a retention rule that guesses wrong costs time and can never change an answer.
  • contains_word(text, name) implies text.contains(name). The verifier's watched set is the whole-word one and the occurrence walk's prefilter is the substring one, so every watched file is one the substring rule retains.
  • The corpus is OpenTitan 00981352642fb65ef2b6c47143a0f6bb31fd4a97 with the three pre-existing modified files, read-only, as in §P0/§P1.

Handshakes

Consumed.

  • vlog_parser::stats::parses() — §P1's per-thread whole-file parse counter. This lane counts deltas around stages and asserts formulas on them.
  • vlog_semantic::workspace: FileFacts::of / IndexBuilder::{new, add_facts, finish} / WorkspaceIndex::{build, absorb, fingerprint} and the contract in docs/topo.md §3 that absorb must equal one build over the resulting record set. P2c depends on exactly that sentence and pins it by test.
  • lucisv_server::state::Workspace::rename_sources' rung ladder — climbed unchanged; only the sink it inserts into changed.

Promised / requested (topo edges for the lead).

  1. vlog_refactor ──▶ vlog_semantic: new additive API FileFacts::analyzed(path, src) -> (FileFacts, Semantics) — FileFacts::of handing back the analysis it read the record off instead of dropping it. No codec change; FACTS_FORMAT untouched (nothing new is persisted).
  2. vlog_refactor public surface: rename_traced and the RenameTrace / VerifyTrace / Stage values. Additive; rename is rename_traced with a trace nobody reads, so there is no second rename path.
  3. lucisv_server ──▶ vlog_refactor: rename::rename_traced replaces rename::rename at the one call site (server/dispatch.rs), and Workspace::rename_sources_traced replaces rename_sources. Both are the old function with an out parameter; the ladder and the engine are unchanged.
  4. lucisv_server internal: new module rename_trace.rs (Rung, Wanted, SelectionTrace) — the path set the fan-out fills, which now remembers which rung filled it.

Not touched. check::verify / verify_splice / verify_move compare exactly what they compared before: token identity, the resolution-identity print, the comments/attributes ledger, parse-diagnostic preservation. Every hunk in check/ changes an input to a check — where a Semantics or an index came from — and none changes a comparison. module_sources, offer_sources and imports::sources are untouched; no selector is narrowed or shared, so handshake 33 stays P2d's prerequisite and is not reached here.

Status / TODO

  • P2a — RenameTrace in vlog_refactor (trace.rs), SelectionTrace in lucisv_server (rename_trace.rs), one timing: rename trace … line behind --verbose, the renametrace harness phase, eight renames measured with peak RSS, tracker rows and experiment P2a-2026-09-07.
  • P2b — one parse + analysis per file inside the request-local scope (FileFacts::analyzed, Scope::build_keeping), experiment P2b-2026-09-07.
  • P2c — the after-index from unchanged facts plus the edited files' one new analysis; untouched watched files re-resolve rather than re-analyse (check/after.rs), experiment P2c-2026-09-07.
  • measured: K + E whole-file parses, asserted; the tail rename 1.86× faster (target ≥2× missed by 28 ms — the remaining stage is named below); aes rename 25 % faster, not slower; every edit, warning and refusal fingerprint identical to the §P0 REF; the queued definition down 24.5 %; peak RSS unchanged or lower on all eight rows.
  • QA.

Work log

2026-09-07 — dev, P2a: the instrument

Files. New crates/vlog_refactor/src/trace.rs (Stage, VerifyTrace, RenameTrace); rename/mod.rs gains rename_traced with rename delegating to it; check/mod.rs::verify gains a &mut VerifyTrace parameter and times its five sub-stages; lib.rs re-exports. New crates/lucisv_server/src/rename_trace.rs; state.rs's five rung functions take a &mut Wanted instead of a &mut BTreeSet<PathBuf> and say which rung they are on (+23 lines net in state.rs — git diff --numstat 35/12, all of it the traced entry point and five wanted.on(…) lines; no selection logic changed); server/dispatch.rs logs one line when --verbose; new tools/perf/phases_p2.py with the renametrace phase and a RSTMGR site.

Deviations from the brief, and why.

  • The trace is an out parameter (&mut RenameTrace, &mut Option<String>) rather than half of the Ok value. A rename that refuses after 2.1 s is one of the seven rows the plan asks for, and a Result<(Edit, Trace), String> throws the trace away on exactly those rows.
  • Workspace::rename_sources and lucisv_server::rename::rename were collapsed into their traced forms rather than kept as one-line wrappers: with the production path on the traced form the wrappers are dead code in a non-test build, and #[allow(dead_code)] on a public method to keep a wrapper alive is worse than the four mechanical .0s it saves. The call sites updated are two benchmarks in perf.rs (outside the brief's file list — flagged here) and four test helpers.

What the 780 ms tail rename is. Repeat medians of four requests, release binary bf584aa0daf6…, renametrace row tail: state_q → state_q_x, wire 781.7 ms:

Stage ms whole-file parses
selection (rename_sources, server) 13.4 0
Scope::build — the index over the input 228.5 238
locate 0.5 1
collect_edits (the occurrence walk) 116.3 134
verify — token identity 4.3 0
verify — before-prints (analyses already cached) 14.0 0
verify — rebuilt_index 228.4 238
verify — after analyses + compare 71.5 106
warnings 83.6 0
total 760.5 of 781.7 717
  • The input is 238 files / 4.55 MB, not the two the edit touches. The rungs: request 1, declaration 95, reference 122, instantiation 19, macro 0, speller 0, open buffer 1. So the "2 files" of the tracker's output row is 0.8 % of the input, and the fan-out is dominated by the declaration and reference rungs of state_q — a name 95 files declare.
  • 717 whole-file parses over 238 files. Every file is parsed for the index, 134 again by the occurrence walk, all 238 again by rebuilt_index, and 106 again for the after-prints. K + E — one parse per input file plus one per edited file — is 240. The other 477 are the duplication §P2b/§P2c exist to remove.
  • The two 228 ms stages are the same work twice: Scope::build and rebuilt_index are both WorkspaceIndex::build over 238 texts, and only two of those texts differ between them.
  • The 83.6 ms of warnings runs zero parses: it is tokenizing, not parsing, and it is out of P2b/P2c's reach.

The other six rows, in one paragraph each's worth of numbers. The ordinary aes rename: 13 files / 400 KB, 51 parses, 140.5 ms — index 23.4, edits 19.2, verify 63.3 (rebuild 22.4, after 20.3), warnings 23.4. A unique internal name (cipher_alert, 4 files): 10 parses, 22.3 ms — the shape the fan-out is built for. A common port name (clk_i at its declaration): the fan-out's ambiguity hatch fires, the input is the whole workspace — 3 976 files / 35.8 MB, 10 399 parses, 7 142 ms, peak RSS 1 864 MiB; the edit is still 2 edits in 2 files. The conflict row (state_q → state_d) refuses correctly after 634 ms, having done 638 parses. A new name a great many external uses spell (cipher_alert → clk_i) refuses after 5 291 ms and 9 229 parses. A duplicate module name (rstmgr_por, declared in four files) takes the same hatch and refuses after 2 116 ms — of which 1 837 ms is a whole-workspace Scope::build and 242 ms the selection, and none of it is the refusal, which locate reaches in 1.8 ms. A cursor on no symbol at all is the same shape through a different door (rename.rs hands ws.sources() over when there is no name to fan out from): 2 111 ms, 3 976 parses.

Where the answer is that the 780 ms goes. 29 % Scope::build, 29 % rebuilt_index (the same build again), 15 % the occurrence walk's re-parses, 9 % the after analyses, 11 % warnings, 2 % selection. 73 % of it is whole-file parsing, and two thirds of that parsing is repeated work.

Reference agreement. Every §P0 REF row was re-taken on this binary and every fingerprint is byte-identical: tail rename b39defb21265… (817.5 / 789.5–782.2 ms against REF 813.4 / 778.8–782.1), aes rename fa7e31c78382… (168.4 / 141.3–140.1 against 167.6 / 140.5–142.1), connect-missing-ports 4b534a16bca7… (174.9 / 164.9–162.8 against 171.4 / 165.8–167.5), expand-wildcard 8f3a26dd147b… (78.4 / 69.8–71.1 against 73.6 / 71.7–73.0), organize-imports resolve 0ee027e37d07…, the extract capture 090e92e7736e… (258.5 / 245.0–243.4 against 257.3 / 245.1–247.0), the definition behind the rename 159.0 / 158.9 / 154.3 (against 163.4 / 161.6 / 161.1). The instrumentation costs nothing measurable, which is what a stage timer and a Cell increment should cost.

QA log

2026-09-07 — QA (Sonnet), P2a/P2b/P2c verification

Scope. TODO §60.2's P2a/P2b/P2c only. Handshake 33 and P2d are not this lane's and are not touched or judged here. Read CLAUDE.md, docs/topo.md, docs/performance_take5.md §P2, docs/perf/take5-tracking.md's P2 rows and experiments, docs/features/refactor-rename/README.md's verification story, the working-tree diff, and the evidence in ~/.cache/lucisv-perf/take5-p2/. Note early: the dev's P2b/P2c work-log entries (§P2b at line 206, §P2c at line 271 of this file) landed after this QA log/Review heading pair instead of under Work log — a structural slip, not a content problem (nothing in them belongs in Review). Flagged for the lead; not reordered here since moving another agent's prose is not a "small unambiguous fix."

1. Gates, guarded, in the main tree. tools/guard.sh -m 8 -t 1800 -- cargo fmt --all -- --check: clean. cargo clippy --all-targets: clean, 0.12 s (cache already warm from the dev's own build); no #[allow] anywhere in git diff. cargo test --workspace: 4231 passed, 0 failed, matches the dev's count exactly; zero guard kills. Load 3.46/4.62/5.07 before, no spike.

Per-crate/binary counts, candidate vs. a HEAD (dafa4f0, the pre-P2 P1c commit) build in a disposable clone (/private/tmp/.../scratchpad/qa-p2/head-clone), both full cargo test --workspace runs (not -p-restricted, so this is the true baseline): HEAD 4215 passed, 0 failed, matching the tracker's stated pre-lane count exactly. Deltas, all growth, none dropped: vlog_refactor unittests 123→135 (+12: 4 in scope::tests, 3 in check::after::tests, 5 in rename::tests); vlog_refactor tests/rename.rs 70→70 (unchanged, as claimed — the refusal-list tests were not touched); vlog_semantic unittests 36→36 (unchanged); vlog_semantic tests/workspace.rs 87→89 (+2: analyzed_gives_the_record_of_gives_and_the_analysis_a_caller_would_compute, an_index_from_analyzed_facts_is_the_index_a_build_gives); lucisv_server unittests 1545→1547 (+2, rename_trace's own tests). Every other crate (vlog_parser, vlog_linter, vlog_formatter, lucisv, lucisv_core) unchanged. 4215+16=4231 ties out exactly to every individual diff above — no test was quietly removed and replaced.

Production line counts: check/mod.rs 405 (measured: everything before #[cfg(test)] at line 603, non-blank non-comment), after.rs 39 (before #[cfg(test)] at line 86) — both match the dev's claim exactly. Nothing over 600. state.rs git diff --numstat: 35 insertions / 12 deletions = net +23, inside the "~20 lines" the brief allowed and matching the dev's own count; the diff is exactly the traced entry point (rename_sources_traced) plus the six wanted.on(Rung::...) lines — no selection-logic line changed.

2. The verifier, hunk by hunk. Read git diff crates/vlog_refactor/src/ check/mod.rs end to end plus the new after.rs. Confirmed: Print, print, anchor_of, Shifts, Excluded, watched_files, tokens_match, first_difference, check/ledger.rs (not in the diff at all — zero changes) and the parse-diagnostic comparison in verify_move are byte-identical in logic; the diff only threads a &mut VerifyTrace/ Stage::measure through the same call sequence and replaces the inline rebuilt_index/re-analyze block with calls to after::{after_index, after_print}. No comparison changed; only where a Semantics/index comes from did.

Pre-existing verifier attacks, re-run. check::tests' tokens_match pairs (8), check/ledger.rs's ~19 _is_rejected/_is_refused tests, removing_an_import_a_reference_needs_is_rejected, crates/vlog_refactor/tests/rename.rs's ~15 refusal tests — all still refuse (covered by the full-workspace green run above; spot-ran check::ledger::tests and tests/rename.rs individually too, both clean).

Sabotage, in a fresh clone (sabotage-clone, git diff patch applied + untracked files copied — verified git status --porcelain matched the working tree before any sabotage) — each reverted immediately after and vlog_refactor --lib re-run clean (135/135) to confirm the revert:

  • (i) stale retained analysis for an edited file. Forced after_print to always take the retained/before-edit analysis, even for edited files (let _ = edited; { scope.against(i, index)... }). Result: 4 tests failed — a_rename_parses_each_input_file_once_and_each_edited_file_once_more, the_traced_rename_and_the_plain_one_are_the_same_call, the_trace_accounts_for_every_parse_the_rename_ran, and (for a revealing reason) a_rename_that_would_make_a_third_files_use_ambiguous_is_refused — whose "an unclaimed name still renames" half now fails because every edited-file rename refuses. The dev's own named target test (a_rename_whose_edit_rebinds_a_name_in_the_edited_file_is_refused) still shows ok, but only because the sabotage's collateral over-refusal masks the narrow capture case — not proof of that one check in isolation. Finding, not blocking: the target attack test alone is not a clean isolation test for this sabotage; the real signal is the 4-test collateral failure, which is unambiguous. Recommend the dev split "capture inside the edited file" from "index/print machinery" more finely if this needs a sharper single-assertion pin later — not required for this lane's merge.
  • (ii) after-index forgetting facts. Two variants: (a) literal reading of the brief — index.absorb(records, &edited_paths_as_gone) — is a no-op (gone is dropped, then the same paths are immediately reinserted from records); all tests still pass. This is a finding: the brief's literal phrasing does not describe a real bug in this API's semantics. (b) the doc comment's own named rejected alternative — drop every unedited file from the cloned index before absorbing (gone = every in-scope path not in edited) — fails 2 tests: an_absorbed_after_index_is_the_index_a_rebuild_would_give and absorbing_an_edited_file_keeps_every_file_id, both immediately and clearly. The dev's named target, a_rename_that_would_make_a_third_files_use_ambiguous_is_refused, still passes under this sabotage too — traced why: dropping b.sv entirely makes use.sv's taken_pkg::V resolve unambiguously to the wrong file (a.sv, freshly re-added) instead of ambiguously, and the resolution-identity check's anchor comparison catches that difference independently (defense in depth) — a legitimate positive finding, but it means the "third file" test is not the one that actually detects index forgetting; the fingerprint/rebuild-equality tests are. Recommend the README's claim ("an after-index built from the edited files alone... — would have forgotten the third file's declaration") cite an_absorbed_after_index_is_the_index_a_rebuild_would_give as the pin, not (only) the third-file rename test.
  • (iii) print keyed by FileId, not path. anchor_of's index.path(def.file) replaced with PathBuf::from(format!("#{}", def.file.0)). Fails exactly and only the named target, a_print_names_paths_so_shifted_file_ids_cannot_change_it, cleanly (left "#0", right "#1" for the same file across two indexes with an inserted-first file). Precise, as predicted.

Two attack pairs of my own, added to the sabotage clone (not merged; disposable), both pass on the real code:

  • qa_after_print_of_an_edited_file_reflects_its_own_edited_text — an ordinary one-file rename's returned edits must rename both the declaration and the use; passes.
  • qa_a_file_retained_only_by_the_substring_rule_never_changes_the_answer — a third file (third.sv) spelling outsig (contains sig as a substring, never as a whole word: contains_word(THIRD, "sig") is false, THIRD.contains("sig") is true) is retained by Scope::build_keeping's substring rule but excluded from watched_files's whole-word rule. Confirms by direct assertion (not just reasoning) that its presence, retained or entirely removed from the workspace, produces byte-identical edits and warnings — the superset claim (retained ⊇ watched) holds and is harmless where it is a strict superset. Passes.
  • Adversarial after-index case of my own, in check/after.rs's test module: qa_an_edited_file_that_declares_a_name_another_file_already_has_is_ambiguous_like_a_rebuild — editing sub.sv to add a second package pkg; (an unrelated file, pkg.sv, already declares pkg) and asserting the absorbed after-index reports pkg exactly as ambiguous as a full rebuild does (fingerprint + file list + per-name answers() all equal). Passes — absorb's merge(None) is a full re-derivation by construction, so this holds by the same argument an_absorbed_after_index_is_the_index_a_rebuild_would_give already pins, but it is now pinned on this specific adversarial shape too.

4. Parse-count formula, sabotaged. Re-added a redundant parse_source_tolerant(text) call inside Scope::analysis unconditionally (even when kept.remove(&i) would hit). a_rename_parses_each_input_file_once_and_each_edited_file_once_more fails immediately: left: 14, right: 10 (the K+E=10 formula breaks the moment locate/edits stop being free). Reverted; test green again.

5. Fingerprint/FileId proofs. Read an_absorbed_after_index_is_the_index_a_rebuild_would_give (9 cases) and absorbing_an_edited_file_keeps_every_file_id — both sound, both already covered above under sabotage (ii-b), which is exactly the sabotage these two tests are built to catch. Added my own 10th adversarial case (above, "an edited file that adds a second declaration of a package already declared elsewhere"); passes.

3. Wire parity, old vs. new — 8 renametrace rows + 5 of my own. Built dafa4f0 (pre-P2, post-P1c) release server in the disposable clone; ran tools/perf/phases_p2.py's renametrace phase against it and against the candidate target/release/lucisv-server (sha256 1601b13a9bacda47095cb23580e475ac8f33a171f446875484439ec67d58eb31 — matches the tracker's P2c entry exactly; no rebuild performed, satisfying item 7's binary-identity check for the re-measurement below too). All 8 rows' fingerprints and refusal sentences byte-identical between the two binaries and equal to the tracker's REF/P2a-c values: b39defb21265…, fa7e31c78382…, 5f53e977da59…, 31aadc134628…, and the shared refusal fingerprint 96f32d4243b1… on all three refusal rows plus the no-symbol row's message. Candidate-side trace fields also reproduce the tracker's numbers exactly (tail: parses 240 = 238+2, rungs_declaration=95 rungs_reference=122 rungs_instantiation=19; clk_i fallback: 3977 parses, fallback=true, selected=3976).

Five renames of my own (tools/perf-style script, run from the QA scratchpad, not committed to the dev's tree): a port (entropy_clearing_ack_i in aes_core.sv, connected from aes.sv), a parameter (SecStartTriggerDelay, used in aes.sv/aes_control.sv/ aes_core.sv), a package member (aes_pkg::AES_OP_WIDTH, used from aes_cov_if.sv/aes_core_fi_vseq.sv), a module with many instantiations (prim_flop_2sync, the 128-file fan-out cursor from sites.FANOUT_CURSORS), and a name inside a generate block (delay_cntr_q in tlul_delayer.sv's gen_delay_logic block). All 5 succeeded (no refusals) on both binaries and all 5 fingerprints are byte-identical HEAD vs. candidate.

git -C ~/repo/opentitan status --porcelain checked after every phase (the 8-row runs ×2 binaries, the 5-row runs ×2 binaries, the P0-run for per-crate test counts does not touch opentitan): unchanged, always exactly the three pre-existing modified files.

6. Memory, re-taken on the candidate. clk_i fallback peak RSS: 1574 MiB (mine) vs. the dev's P2c 1830 MiB — lower, not higher (no "exceeds by >10%" concern; if anything the gap the other way is larger than 10%, plausibly host load variance between runs — flagged, not blocking, since "lower" cannot itself be a corruption or perf regression). Tail rename peak RSS: 584 MiB (mine) vs. dev's 593 MiB — within 2%. Neither approaches the 8 GiB guard (fallback is 19% of it).

7. Re-measured on the P2c binary. Binary confirmed byte-identical to the tracker's P2c entry by sha256 (above) — no rebuild. renametrace's ms medians on my run: tail 421.0 (dev 419.9, +0.3%), aes 106.8 (dev 106.3, +0.5%), clk_i fallback 3882.7 (dev 3860.1, +0.6%) — all within ±10%, fingerprints identical (above). Did not re-run tailrename / rename / blockers / refactor / execute as separately-named bench.py phases beyond renametrace's own tail/aes rows and the fingerprint survey in item 3, given time budget; the tracker's own P2c figures for those rows are independently corroborated by the traceability check below (item 8) reading the same raw evidence files the dev's prose quotes.

8. Traceability — 15+ numbers cross-checked against ~/.cache/lucisv-perf/take5-p2/*.jsonl directly (not just the README's prose): results-p2a.jsonl's tail row: trace_parses_index=238, trace_parses_locate=1, trace_parses_edits=134, trace_parses_rebuild=238, trace_parses_after=106, summing to 717, matching trace_parses=717 exactly. results-p2c.jsonl's tail row: 238+0+0+2+0 = 240, matching trace_parses=240. results-probe-updatefacts.jsonl's trace_verify_rebuild: tail 53.3, aes 40.2, clk_i 400.9 — exactly the "two update_facts" numbers the README's P2c work-log quotes. results-p2c.jsonl's own trace_verify_rebuild for the same three rows: 37.2, 23.4, 269.7 — exactly the "one absorb" numbers the same paragraph quotes. All eight renametrace fingerprints (item 3). The P2c sha256 (item 7/3). Stage-sum arithmetic (this item). That is 8 (fingerprints) + 6 (rebuild-cost pairs) + 1 (sha256) + the two parse sums = well over 15 independent numbers, all reproduced from the raw .jsonl, not taken on faith from the README's prose.

9. The --verbose trace line. Ran the tail rename twice from a disposable script: once with verbose=False (0 timing: rename trace lines in window/logMessage), once with verbose=True (exactly 1 line, 419 characters, no embedded newline, fields in the documented order). Confirms the line is verbose-gated and single-line as claimed.

Guard / resource notes. Every cargo command and every server session above went through tools/guard.sh -m 8 -t 1800. Zero guard kills across the whole QA pass. No cargo command ran concurrently with a timed phase (checked ps before each; the one background cargo build --release for the HEAD comparison binary completed before any timed harness run started). Peak RSS on every row stayed far under the 8 GiB limit (worst case ~1.6 GiB).

Verdict: PASS, for P2a/P2b/P2c only. Findings above are non-blocking (one documentation-structure slip, two notes about which existing test actually pins which sabotage class, one note that the dev's cited literal-gone sabotage reading is a no-op) and are recorded for the lead and for whoever picks up P2d/handshake 33 next, not required fixes for this merge. Handshake 33 and P2d remain open and are not judged here.

Review

2026-09-07 (lead, P2a–P2c). Accepted. Read scope.rs's assemble / build_keeping / against, check/after.rs and every hunk of check/mod.rs, trace.rs, rename_trace.rs, the tracker's three experiment entries and both logs; QA's independent HEAD baseline (4215 → 4231, no test dropped) and its wire parity over thirteen renames are the acceptance.

  • P2a is the finding that shaped the rest: "2 files" was 238 input files, 4.55 MB and 717 whole-file parses, two thirds of them repeated — one WorkspaceIndex::build over 238 files twice, and every watched file twice more. The trace makes that visible on the --verbose channel and nowhere else, which is the right place.
  • P2b/P2c are the boring version of the fix: the index build hands back the analysis it already made (FileFacts::analyzed, of = .0 so no drift), the request's own file is analysed first so the cursor's name is known before the rest are parsed, retention is a cache and never an oracle, and the after-index is the before-index plus the edited files' absorbed records. Every hunk in check/ moves an input; no comparison changed, and the three new attack pairs plus QA's two say so. K + E parses, asserted from the trace, is the invariant the next round inherits.
  • Target: tail rename 780 → 420 ms (1.86× against the 2× goal, short by 30 ms); the remaining 225 ms is one parse of each of the 238 selected files, so the lever left is the selection — P2d, behind handshake 33, in its own lane. aes rename −25%, both resolves −20%, the extract capture −39%; the aes_wrap.sv extract refusal unchanged because it is selection (a package name's module_sources), the same lever.
  • QA's non-blocking findings noted: attack (i) is caught by collateral refusals rather than by its named test alone, and attack (ii)'s literal form is a no-op while its stronger form fails the pinning tests — both are defence in depth working, and the named tests stay as the pins.
  • Memory: peak RSS moved by less than 20 MiB everywhere and fell on the two heaviest renames; the fallback stays at 1.8 GiB, the number P2d should also bring down.
  • Deviations accepted: the trace as an out parameter (refusals traced too), the collapse of the untraced wrappers, the two touched files outside the list (perf.rs call sites, one mod line).

Docs applied at merge: topo edges (1)–(4) from Handshakes.

2026-09-07 — dev, P2b: one parse per file inside the scope

The additive semantic API. FileFacts::analyzed(path, src) -> (FileFacts, Semantics) (vlog_semantic/src/workspace/record.rs). facts_of's body is now this function, and facts_of is analyzed_facts(path, src).0 — so the record cannot depend on which was called, and there is no second read-off to drift. No codec change: nothing new is persisted and FACTS_FORMAT is untouched. The approach the brief named first — rebuilding a record with FileFacts::from_analysis — was rejected because that constructor needs the token slice the parser consumes, so a caller would have to clone every file's tokens to feed it; handing back the analysis the read-off already used costs nothing and cannot disagree.

The scope. Scope::assemble replaces WorkspaceIndex::build with an IndexBuilder loop over FileFacts::analyzed, so each file is parsed and analysed exactly once and the analysis is kept rather than dropped. Scope::build(files) keeps none — every existing caller (ports, imports, extract, inline, references) behaves and costs exactly as before. Scope::build_keeping(files, lead, keep) is the rename's: it analyses lead (the request's own file) first, hands that analysis to keep, and retains every file whose text contains one of the words keep names. Scope::analysis(i) takes the retained Semantics when there is one and parses otherwise, so retention is a cache and never an oracle.

Why the lead-first ordering. The words worth keeping are the new name and the name under the cursor, and the cursor's name is only knowable from the cursor file's analysis. Analysing it first makes that analysis the file's own one-and-only parse instead of an extra one, which is what keeps the budget at K rather than K + 1. The name is read with rename_name_at — the same function the server's fan-out is built from, whose agreement with the target the rename acts on is already pinned by the_name_a_fan_out_is_built_from_is_the_name_the_engine_acts_on.

Why a substring test and not contains_word. collect_occurrences' prefilter is text.contains(&target.name) and the verifier's watched set is contains_word, which is a subset of it. Retaining on the substring rule therefore covers every file either of them will ask for, and nothing else.

Memory, which is why retention is not unconditional. §P2a measured the all-sources fallback (clk_i, 3 976 files / 35.8 MB) at 1 864 MiB peak while holding ~1 250 analyses. Retaining all 3 976 would have been roughly 0.8 MiB × 3 976 ≈ 3.9 GiB on top of the index — inside the 8 GiB guard but a 2× regression on a row that is already the worst. The keep rule holds the retained set to exactly the files the request was going to analyse anyway, and the measurement says so: the fallback's peak went 1 864 → 1 840 → 1 830 MiB across §P2a/§P2b/§P2c, and the cipher_alert → clk_i row 1 809 → 1 695 → 1 590. No row's peak rose by more than 20 MiB.

Measured (release e555e6c79d8d…, repeat medians of four requests, load 5.1 → 3.8, corpus unchanged after every phase, zero guard kills). Tail rename 781.7 → 676.6 ms, parses 717 → 582 — locate 1 → 0 and the occurrence walk 134 → 0. aes rename 140.5 → 122.6, parses 51 → 38. Every fingerprint unchanged.

Tests. analyzed_gives_the_record_of_gives_and_the_analysis_a_caller_would_compute (vlog_semantic/tests/workspace.rs) — the record and its encoded form against FileFacts::of, and the analysis against analyze(&parse_source_tolerant(src).0, src), over the crafted set the existing from_analysis equality test uses (which is now a shared crafted_sources()); an_index_from_analyzed_facts_is_the_index_a_build_gives — fingerprint and file list. In vlog_refactor, four scope::tests: the same index however it is assembled, a retained analysis equal to the on-demand one file by file, the lead's analysis available to the retention rule, and a lead outside the scope retaining nothing without failing.

2026-09-07 — dev, P2c: the after-index from unchanged facts

New module crates/vlog_refactor/src/check/after.rs (39 production lines), holding the two functions that build the state after the edits, out of check/mod.rs (427 → 405 production lines) so each file keeps one sentence.

  • after_index(scope, edited) — the before-index cloned and absorbed, plus the edited files' one new analysis each, handed back for their after-prints. It replaces rebuilt_index, which was WorkspaceIndex::build over every in-scope text.
  • after_print(scope, i, path, index, edited, excluded) — the edited file's own new analysis when the edits touched it, and otherwise the analysis the before-pass already computed, re-resolved against the after-index (Scope::against). It replaces the analyze(&parse_source_tolerant(text).0, text) both verify and verify_move ran for every watched file.

Every hunk changes an input, never a check. verify still compares token identity over each edited file, the before-print against the after-print for every watched file, and (in verify_move) the comments/attributes ledger and the parse-diagnostic count. Print, print, Shifts, Excluded, watched_files, tokens_match and first_difference are untouched. The refusal sentences are the same strings.

absorb against update_facts, measured. The plan warned that an incremental-looking API may still rebuild global tables, and absorb does: merge(None) clears every table and re-pushes from all records. update_facts per record uses the restricted merge instead. It is slower: the tail rename's rebuild stage was 37.2 ms with one absorb and 53.3 ms with two update_facts, the aes rename's 23.4 against 40.2, the clk_i fallback's 269.7 against 400.9 — the restricted merge walks the same records and pays a name-set lookup at every declaration, which costs more than the push it skips. absorb kept; the probe's rows are in ~/.cache/lucisv-perf/take5-p2/results-probe-updatefacts.jsonl. Either way the parse saving stands: the after-index costs E parses, not K.

Measured (release 1601b13a9bac…, repeat medians of four requests, load 5.2 → 2.8, corpus unchanged after every phase, zero guard kills).

Row §P0 REF §P2a §P2b §P2c vs REF
tail rename (tailrename) 780.45 784.19 674.68 419.86 −46.2 %
aes rename (rename) 141.30 140.15 123.08 106.31 −24.8 %
definition behind the rename (blockers, mean of pipelines 2–3) 161.33 156.48 141.64 121.85 −24.5 %
connect missing ports resolve 166.51 164.91 165.29 132.72 −20.3 %
expand wildcard resolve 71.89 70.31 70.29 54.91 −23.6 %
extract command executed (execute) 246.03 244.53 244.78 149.25 −39.3 %
extract refused at aes_wrap.sv 66:2 ~801 802.03 802.07 801.23 0 %
organize-imports resolve 9.45 11.99 11.18 8.51 −10 %

Whole-file parses on the tail rename: 717 → 240, which is K + E = 238 + 2, asserted as a formula by a_rename_parses_each_input_file_once_and_each_edited_file_once_more. On the all-sources fallback: 10 399 → 3 977. Every fingerprint on every row is byte-identical to the §P0 REF's (b39defb21265…, fa7e31c78382…, 4b534a16bca7…, 8f3a26dd147b…, 0ee027e37d07…, 090e92e7736e…), and the three refusal rows carry the same sentences and the same empty-edit fingerprint 96f32d4243b1….

The target that was missed, and the stage that is left. ≥2× on the tail rename needed 390.2 ms; the measurement is 419.9, i.e. 1.86×, short by 29.7 ms. The trace says exactly where the remaining 418 ms is:

Stage ms share parses
Scope::build — one parse of each of the 238 selected files 225.1 54 % 238
warnings — a token scan of every file spelling the name 83.3 20 % 0
verify 73.0 17 % 2
… of which the after-index (clone + absorb) 37.2 9 % 2
… before-prints 14.0 3 % 0
… token identity 4.5 1 % 0
… after-prints 7.9 2 % 0
selection (server fan-out) 13.4 3 % 0
collect_edits 12.1 3 % 0
server + transport + position conversion ~11 3 % —

There is no duplicated parsing left to remove. The 225 ms is the first and only parse of each selected file, and the only way past it is to select fewer files (§P2d, which is not this lane) or to hand the engine records the server's own index already holds (a step §P2b's plan deliberately defers, because file ids and the subset's resolution universe differ). The 83 ms of warnings is tokenize + LineIndex per file that spells the name — not a parse, already guarded by the same prefilter, and untouched by this lane.

Tests. check::after::tests — an_absorbed_after_index_is_the_index_a_rebuild_would_give compares fingerprint, file list and a query-level print (units, references_to, instantiations_of, hierarchical_declarations, workspace_symbols) against a full rebuild on nine cases: an ordinary one-file and two-file rename edit, a file that gains a declaration, one that loses it and leaves a dangling use, an edit that changes what another file resolves to, an edited package under a re-export chain, an exported chain losing its export, a module that stops being instantiated, and an edit that makes a file stop lexing. absorbing_an_edited_file_keeps_every_file_id pins id stability.

The three new attack pairs, aimed at the reuse itself:

  1. a_rename_whose_edit_rebinds_a_name_in_the_edited_file_is_refused — an edited file whose after-print came from the before analysis would describe text that no longer exists. The rename gives sig the name of an existing taken in the same file, which only a print of the edited text can catch; it is refused.
  2. a_rename_that_would_make_a_third_files_use_ambiguous_is_refused — an after-index built from the edited files alone (or absorbed with a wrong gone) would have forgotten the untouched b.sv. The rename renames a_pkg to a package b.sv already declares, and the refusal is about use.sv, which is neither edited nor mentioned by the edits. The same test asserts an unclaimed new name still renames, so the refusal is not blanket.
  3. a_print_names_paths_so_shifted_file_ids_cannot_change_it — the same file's print against two indexes whose FileIds differ by one everywhere must be the same print, so the comparison cannot start depending on the id stability absorb happens to give.

Every existing verifier attack is untouched and still refuses: check::tests' eight tokens_match pairs, the ledger attacks in check/ledger.rs, removing_an_import_a_reference_needs_is_rejected, and the rename refusals in rename/tests.rs and tests/rename.rs.

Test counts. 4 215 before this lane → 4 225 after §P2b → 4 231 after §P2c; no test was removed or weakened. cargo fmt --all -- --check clean, guarded cargo clippy --all-targets clean with no new #[allow], guarded cargo test --workspace green before each of the three release builds. No cargo command ran during any timed phase; zero guard kills; git -C ~/repo/opentitan status --porcelain showed the same three files after every one of the nineteen timed phases.

Deviations and things the lead should rule on.

  • Scope::sources() was deleted: rebuilt_index was its only caller.
  • crates/lucisv_server/src/perf.rs (outside the brief's list) — two benchmark call sites moved to rename_traced / rename_sources_traced, mechanical.
  • crates/lucisv_server/src/main.rs (outside the brief's list) — one line, mod rename_trace;, which is how the new module is reachable at all.
  • Not done, deliberately: the extract refusal at aes_wrap.sv 66:2 is still ~801 ms. It refuses immediately after Scope::build, so there is no repeated analysis to remove; its cost is module_sources selecting hundreds of files for a package name, which is the §P1 finding filed for §P2d and handshake 33.