Files
lucisv/docs/features/perf5r-scope-reuse/README.md
T
Guoliang ChenandClaude Mythos 5.2 71d13b5fbe
ci / checks (push) Successful in 1m0s
ci / corpus (push) Successful in 18s
ci / linux (push) Successful in 6m4s
release / build-and-publish (push) Successful in 5m31s
Release 0.66.2: every source file names its author
Every tracked file that can carry a comment (880 of them) now opens with
"Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with
"Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love,
luciochen.com", in the file's own comment syntax. No behaviour change: the
diff outside the version bump and changelogs is comment lines only.

- tools/stamp_author.py: writes the lines; idempotent, `--check` lists
  what is missing. Headers go under a shebang and under Markdown front
  matter.
- Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON
  and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the
  LICENSE files (already carry the copyright line).
- tools/linux_check.sh: --help reads its header from line 3, now that the
  author line sits under the shebang.
- tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-24 12:11:09 -08:00

664 lines
41 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
# perf5r-scope-reuse — the rename's scope stage, measured and then reused
Take 5 **review round** §3 items 1–4 (`docs/performance_take5_review.md`),
TODO §61.5, tracker rows **R3c** (measure) and **R3b** (reuse). Reference
tree `07ef771` — §61.1–§61.4 already merged, so the cheap refusals of §61.1
are already gone and what is left on the slow road really is the scope build.
## Goal
A hierarchical `state_q` rename on OpenTitan costs about 400 ms, and §P2a's
trace says **229 ms of it is the scope build** — one parse and one analysis of
every one of the 238 selected files. §P2d already proved the *selection* is
not the lever: 133 of those files are containers a hierarchical tail folds
through, needed for the **index** and for nothing else. This lane asks the
other half of that question — whether a file needed only for the index has to
be *parsed* to get there — and it asks it in two steps, in this order:
1. **R3c, measurement.** Split the 229 ms into what it is made of, ship the
split in the engine's own trace, and write down the number that decides
whether step 2 happens at all.
2. **R3b, the reuse**, conditional on that number.
The answer to step 1 was **go at 34.3 %**, and step 2 is a door
(`vlog_refactor::KnownFacts`) through which a caller hands back the index
record it already holds for the exact bytes it is handing over. The engine
skips that file's parse and nothing else changes: same edits, same warnings,
same refusals, same index (asserted by fingerprint), verifier untouched.
## Assumptions
- **The persistent index cache is the only thing that can keep the
`KnownFacts` promise in this server.** It is the one place that holds a
record *and* the FNV-1a of the bytes that record was read off, written by
the same read. The workspace index holds decoded records with no hash
beside them, so it cannot be the source: a record filed under a path is not
evidence about the text a rename was just handed. This is stated as an
assumption because it is a property of today's `Workspace`, not something
the type system enforces — see Handshakes.
- Nothing downstream of the scope build reads a *non-kept* file's analysis.
This is §P2b's own rule, restated: the retention rule is
`text.contains(word)` for the old and the new name, and every later
consumer — `collect_occurrences`, all five warning scans, `check`'s watched
set — prefilters on `contains` or `contains_word` of one of those two
names, which is a subset. A reused record therefore never denies a later
stage an analysis it asks for; and if one ever did, `Scope::analysis`
parses on demand exactly as it always has.
- The cache's decode of a record produces the record the parse would have
produced. That is `docs/features/index-persistence/README.md`'s own
invariant, and every warm scan in the product already rests on it — this
lane adds a second reader of the same answer, not a new claim.
- A rename request runs on the server's main thread, which has
`vlog_parser::PARSE_STACK_SIZE`. Unchanged: the reuse removes parses, it
never adds one anywhere new.
## Handshakes
**`lucisv_server ──▶ vlog_refactor` (new, additive).**
`rename_traced_with(files, file, offset, new_name, &dyn KnownFacts, &mut
RenameTrace)` is `rename_traced` plus one question the engine asks per
selected file: *do you have the record `FileFacts::of(path, text)` would
produce for exactly this text?* The engine promises that a `None` answer
costs nothing but the file's usual parse, and that a `Some` answer changes
only what it costs — the record is fed to `IndexBuilder::add_facts`, which is
the same call the persistent cache's own scan hits make.
What the **caller** promises is the whole of the contract, and the engine
cannot check it: verifying a record against the text it claims to describe
means doing the parse the record exists to save. The engine does the two
checks it can — it asks with the exact text it is about to index, and it
refuses a record whose own `path()` is not the path it asked about — and
trusts the rest. `crates/lucisv_server/src/rename.rs::Known` is the one
implementation: a newtype over `&Workspace` whose entire body is
`Workspace::known_facts`, so the promise is kept in exactly one place.
**Inside `lucisv_server` (no crate boundary crossed).**
`Workspace::known_facts(path, text)` → `IndexCache::facts_now(path, text)` →
`IndexCache::entry_for(path, text)`, which is now the single place where a
record and the content hash it is filed under are compared. `facts_for` (the
scan's counted reader) goes through the same function, so "the store answers
for this text" means one thing in a scan and in a refactoring alike.
`facts_now` differs from `facts_for` only in not counting its work into
`IndexCache::work`, because that counter is what a scan's trace subtracts to
say what *that scan* did.
**No handshake is requested and none is amended.** `vlog_semantic` is
unchanged (`FileFacts::path`, `FileFacts::of`, `IndexBuilder::add_facts` and
`WorkspaceIndex::fingerprint` were all already public and already used this
way). `check/` has no diff. `docs/topo.md` needs one new row for the
`KnownFacts` edge — the lead's to write at merge, per this lane's scope.
## The R3c measurement
`renametrace`, candidate-only, one `--verbose` session per row, repeat median
of three; trace fields off the wire. Machine load 4.1–5.1. The `index`
column is the whole scope stage; `lead`/`kept`/`other` are the per-file-class
split this lane added, and `merge` is `IndexBuilder::finish`.
| rename | wire | index | lead | kept | other | **other / index** | merge |
|---|---:|---:|---:|---:|---:|---:|---:|
| **tail `state_q`** (238 files) | 401.2 | 242.4 | 0.4 | 133.5 | **83.1** | **34.3 %** | 23.4 |
| ordinary `aes` (13) | 91.5 | 23.9 | 0.3 | 20.8 | 0.0 | 0.0 % | 2.7 |
| unique internal `cipher_alert` (4) | 16.9 | 3.6 | 2.4 | 0.0 | 0.9 | 25.0 % | 0.3 |
| common port `clk_i` (3 976, fallback) | 3 551.4 | 1 936.5 | 0.4 | 1 032.0 | **693.4** | 35.8 % | 195.3 |
| conflict `state_q → state_d` (242) | 342.7 | 240.3 | 0.4 | 135.4 | 79.2 | 33.0 % | 23.2 |
| new name many uses spell (3 976) | 2 971.6 | 2 009.8 | 2.9 | 1 067.3 | 724.5 | 36.0 % | 198.0 |
| duplicate module `rstmgr_por` (3 976) | 2 279.4 | 1 982.9 | 1.9 | 5.6 | **1 740.5** | **87.8 %** | 199.6 |
| no symbol (preflight) | 0.1 | 0.0 | — | — | — | — | — |
File counts: the tail selects 238 and keeps 134 of them, so **103 files are
analysed for their index record and nothing else**. (§P2d's census counts 133
"indirect" files by the index's postings; the retention rule's substring test
is wider, so 30 of those do spell one of the two names somewhere and are
kept. The two numbers answer different questions and both are in the trace.)
**Inside one file's analysis** — a *trace-only* build, measured once and not
shipped (the same protocol §R1b used), expanding `FileFacts::analyzed` over
the public API so its four parts can be timed apart. One deviation from the
private body, counted under read-off: `FileFacts::from_analysis` clones the
define table where the private path moves it.
| rename | lex (+`define` table) | parse | analyse | read-off |
|---|---:|---:|---:|---:|
| tail `state_q` | 70.2 (34 %) | 66.2 (32 %) | 40.4 (20 %) | 27.1 (13 %) |
| common port `clk_i` | 604.3 (37 %) | 561.4 (35 %) | 252.0 (16 %) | 195.6 (12 %) |
| duplicate module | 606.9 (37 %) | 568.6 (35 %) | 260.4 (16 %) | 197.6 (12 %) |
So the review's "parser versus index optimization" question has an answer:
**the scope stage is two thirds lexer-and-parser**, the semantic analysis is
a sixth of it, and the index merge is a further 10 % on top (`merge`, above).
Nothing inside the parse is a lever on its own; what is a lever is not
running it.
**Allocation.** No per-stage byte counter exists and none was added: counting
allocations needs a `GlobalAlloc` wrapper, which is `unsafe` (CLAUDE.md
forbids it) — so allocation is reported as the harness's own 50 ms peak-RSS
sample across the request, per row, and as the bytes each class carries
(`kept_bytes` / `other_bytes` in the trace). Tail: 606 MiB peak, 2.89 MB kept
against 1.65 MB unread. Common port: 1 897 MiB peak against 19.9 MB kept and
15.9 MB unread — the peak is where the `Semantics` of 1 248 files sit.
**The warning pass**, split into its five scans (§3 item 3):
| rename | warnings | `define` | macro args | SVA | unfinished | unaccounted | files lexed |
|---|---:|---:|---:|---:|---:|---:|---:|
| tail `state_q` | 49.7 | 1.9 | **41.7** | 2.6 | 0.4 | 0.0 | 135 |
| ordinary `aes` | 8.3 | 0.2 | 7.1 | 0.2 | 0.0 | 0.2 | 13 |
| common port `clk_i` | 431.5 | 13.2 | **371.4** | 15.3 | 4.1 | 0.2 | 1 249 |
**The 51 ms warning pass is 84 % one lex per file that spells the name**, and
that lex is *already* shared by all five scans (§P2d's `FileScan` memo) — the
macro-argument scan is simply the first one to ask for it, so the shared lex
is billed to it. There is no duplicated work left in the pass to remove. The
only way to remove the lex itself would be to retain the scope build's token
streams for every kept file, and the `clk_i` row is why that was not done:
1 249 files of retained tokens against a request that already peaks at
1.9 GiB is a memory trade the review's own gate ("bounded peak RSS") forbids.
Recorded as measured-and-declined, not as unexamined.
### The ruling
**Go — 34.3 %** on the tail rename (83.1 ms of 242.4 ms), against a 30 %
condition. Every other multi-file row agrees (25 %, 33 %, 35.8 %, 36 %, and
87.8 % on the duplicate-module refusal), and the two rows where it is 0 % are
the ones where every selected file spells the name, which is exactly the case
the reuse is not for.
## The R3b reuse
**What was built.** One question, asked once per selected file, before that
file is analysed:
```rust
pub trait KnownFacts {
/// The record `FileFacts::of(path, text)` would produce, if the caller
/// can promise it is exactly that; `None` otherwise.
fn facts_for(&self, path: &Path, text: &str) -> Option<FileFacts>;
}
```
`Scope::assemble` classifies each file first (`Lead` / `Kept` / `Other` — the
same `text.contains(word)` rule as before, only asked before the analysis
rather than after it), then takes its contribution:
| the caller answers | `Lead` / `Kept` | `Other` |
|---|---|---|
| a record | the record + `analyze(parse(text))` — the parse is still owed, because a later stage reads the `Semantics` | the record, **and no parse at all** |
| `None` | `FileFacts::analyzed(path, text)` — exactly as before | exactly as before |
So the parse formula `K + E` becomes **`(K − reused_other) + E`**, and the
reuse also removes the record read-off (`Census`, the `define` table, the
line index, `facts_from_analysis`) from every kept file whose record is
known. The two halves of a reused kept file — the record from the caller, the
`Semantics` from this text — agree because both are pure functions of the same
bytes; that pairing is not new, it is what `Scope::analysis`'s on-demand path
and the server's own warm scan step have always done.
**The hash tie, and where record and hash come from.** `Workspace::known_facts`
is one line: `self.cache.facts_now(path, text)`. `IndexCache` files every
record under the FNV-1a (`lucisv_core::cache::content_hash`, the same one
function, never a second implementation) of the bytes it was read off, in the
same store entry as the encoded record; `entry_for` is the only comparison
anything makes against it, and both the scan's reader and this one go through
it. So the record and its key are read from **one place**, written by the read
that produced them. Nothing weaker is consulted: not a modified time, not a
size, and — deliberately — **not the workspace index's own record**, which
carries no hash of the bytes it came from and could be a record of some other
text filed under this path.
**Unsaved-buffer precedence needs no rule.** A buffer with unsaved edits is
not the bytes any record was written from, so it misses and is parsed —
the same way a changed file misses. The handed text *is* the buffer's text
(`rename_sources_traced` puts every open buffer in the set with
`current_text`), and the reuse never looks anywhere else.
**Cross-file resolution is rebuilt for the candidate workspace, untouched.**
Reuse changes only where a `FileFacts` came from; `IndexBuilder::finish` still
sorts, assigns file ids and merges, and `resolve_external` still runs against
*that* index. `check/` has no diff.
**What was deliberately not built.** An open document's finished analysis
(`doc.tree` + `doc.semantics`) could be handed in as well, saving the parse of
the one or two open buffers among 238 files. It is 1–2 parses of ~0.8 ms
against a `Semantics` clone into the scope, and the door for it would have to
carry an analysis as well as a record. Not worth the second shape; the record
half of an open buffer is already reused whenever the buffer is saved.
No persistent decoded-analysis cache was added, so there is no new memory
budget to state: the reuse retains nothing past the request, and the records
it clones are dropped with the scope.
## The R3b measurement
Paired against a reference built from the clean tree at **`07ef771`** before
any edit of this lane
(`50d8315a738103f006a28e1f6ea46c476a776fff1d880b860fc1bbcd83b315e9`);
candidate `a041b5f3272ca8ff39d9d62e4ab46c896e82b43d0f4e37e11d96b27635f7d491`.
Both `--release --locked`, both through the same harness, `--tries 3`, repeat
median of three, **each phase run twice per binary with the order alternated**
(head, r3b, r3b, head) and the two medians taken. No `cargo` ran during any
timed phase; machine load 3.9–5.1 throughout; every command under
`tools/guard.sh -m 8 -t 1800`, no guard kill.
| row | HEAD | R3b | Δ | parses | reused | peak RSS |
|---|---:|---:|---:|---:|---:|---:|
| **tail `state_q`** | 380.2 | **314.0** | **−17.4 %** | 240 → **137** | 238 | 615 → **596** MiB |
| ordinary `aes` | 89.4 | 88.9 | −0.5 % | 22 → 22 | 13 | 448 → 448 |
| unique internal `cipher_alert` | 16.9 | 15.2 | −9.8 % | 5 → 2 | 4 | 425 → 421 |
| common port `clk_i` (fallback, 3 976) | 3 346.5 | **2 762.5** | −17.4 % | 3 977 → **1 251** | 3 976 | 1 881 → **1 787** |
| conflict `state_q → state_d` (refused) | 320.5 | 260.1 | −18.8 % | 244 → 144 | 242 | 534 → 535 |
| new name many uses spell (refused) | 2 689.0 | 2 191.5 | −18.5 % | 3 976 → 1 250 | 3 976 | 1 571 → 1 587 |
| **duplicate module `rstmgr_por`** (refused) | 2 053.1 | **695.2** | **−66.1 %** | 3 975 → **14** | 3 976 | 887 → **718** |
| no symbol (preflight) | 0.17 | 0.19 | +10.8 % | 0 → 0 | 0 | 417 → 417 |
| `tailrename` phase | 380.0 | 336.7 | −11.4 % | — | — | — |
| `rename` phase, `aes` | 90.8 | 92.0 | +1.3 % | — | — | — |
| `blockers`, rename on `aes` | 115.1 | 114.9 | −0.1 % | — | — | — |
| `execute`, extract refusal (805 ms row) | 800.2 | 794.7 | −0.7 % | — | 0 | — |
| `execute`, extract-module edit | 147.7 | 148.3 | +0.4 % | — | 0 | — |
| `execute`, inline refusal | 6.5 | 6.3 | −3.3 % | — | 0 | — |
| `refactor`, connect-missing-ports resolve | 131.1 | 130.5 | −0.5 % | — | 0 | — |
| `refactor`, expand-wildcard resolve | 54.1 | 54.9 | +1.4 % | — | 0 | — |
| `refactor`, organize-imports resolve | 8.1 | 8.0 | −1.2 % | — | 0 | — |
Where the tail's 66 ms went, from the trace: index **219.8 → 156.2 ms**, of
which `other` **83.1 → 0.0** (the container files stopped being parsed),
`kept` **133.5 → 101.6** (their record read-off stopped being made), `merge`
22.7 unchanged, and the reuse itself **31.1 ms** — 238 store lookups and
decodes at about 0.13 ms each. Every stage outside the scope build is level:
`verify` 71.6 → 71.6, `warnings` 50.1 → 50.2, `edits` 12.3 → 11.9, selection
13.7 → 12.9.
### Gates
| gate | result |
|---|---|
| **≥ 20 % wire on the large rename** | **MISSED at −17.4 %** against this session's paired HEAD (380.2 → 314.0). Against the review's own 0.51.0 baseline of 398.3 ms it is −21.2 %, and the brief's absolute form of the same gate — **≤ 318 ms — is met at 314.0** |
| bounded peak RSS | **met**, and lower everywhere it moves: tail 615 → 596 MiB, fallback 1 881 → 1 787, duplicate-module refusal 887 → 718; the one row that rose (+16 MiB on a 1.6 GiB refusal) is inside the sampler's spread |
| `aes` not slower | **met**: −0.5 % (`renametrace`), +1.3 % (`rename`), −0.1 % (`blockers`) — all inside spread |
| the fallback and the refusals not slower, RSS not higher | **met**: `clk_i` −17.4 %, conflict −18.8 %, new-name-many-uses −18.5 %, duplicate module −66.1 %, extract refusal −0.7 %, inline refusal −3.3 %; RSS lower or level on every one |
| same edits / warnings / refusals | **met**: 36 paired rows compared on `fingerprint`, `message`, `status`, `result_count`, `edits`, `files`, `created`, `titles` — **0 mismatches**; and the new `renamewarn` phase compared **1 750 warning sentences line by line** across four renames (434 / 12 / 0 / 1 304), **all identical** |
| the corpus probe | `a_corpus_rename_says_the_same_thing_however_many_records_are_reused` (`#[ignore]`d, `crates/vlog_refactor/tests/corpus.rs`): one rename over **860 files of real RTL** asked three ways — no records, every record, every second record — **byte-identical edits and warnings all three times**, parses **865 → 16 → 439**, index stage **1 262.4 → 201.3 → 744.7 ms** |
| verifier untouched | **met**: `crates/vlog_refactor/src/check/` has no diff, and every existing verifier attack test is green and unmodified |
**The named remaining stage.** The reuse's own **31.1 ms of decode** is a
third of the gross 95 ms saving, and it is the price of the one-place content
tie: the record and its hash live in the store's encoded entry, so taking one
means decoding it. Taking the *decoded* record from `WorkspaceIndex` instead
and only the hash from the cache would remove almost all 31 ms and clear the
percentage gate — and it is exactly the two-place tie this lane refused,
because a record filed under a path is not evidence about the bytes a rename
was handed. Behind it, the tail's next stages are `verify.rebuild` **37 ms**
(`WorkspaceIndex::absorb`'s whole-index merge, which §61.4 already filed as
`vlog_semantic`'s to fix) and `merge` **23 ms** (`IndexBuilder::finish`, the
same merge). Both are outside this lane's files.
### Collateral: the other refactorings
**Not taken, and the rows above are the measurement.** The door is engine-wide
by construction — `Scope::assemble` takes the `known` argument, so
`Scope::build`'s callers could be given it — but reaching them means a `_with`
entry point on each of `extract_module`, `inline_module`, `organize_imports`,
five `ports::*` functions and `find_references`, in five files this lane does
not own (`extract/`, `inline/`, `imports.rs`, `ports/`, `references.rs`).
That is well past the "same three lines each" condition, so it is filed rather
than done. The measured collateral today is therefore nil, as the table shows:
the 805 ms extract refusal, the extract edit, both resolves and the inline
refusal are all within ±1.4 % of HEAD.
Worth noting for whoever takes it: the 805 ms refusal was shown by R3c-x to
be `boundary::Crossing::read`, *after* the scope build, so the door would
shorten its prefix and not its cause — the resolves and the extract edit,
whose scope builds are hundreds of files, are the better candidates. Neither
has a stage trace, so no estimate is offered here.
## Status / TODO
- [x] R3c: the scope stage split, shipped in the engine's own trace
(`IndexTrace`: lead / kept / other / reused / merge, with files and
bytes per class)
- [x] R3c: the intra-analysis split (lex / parse / analyse / read-off) from a
trace-only build, measured once and not shipped
- [x] R3c: the warning stage split into its five scans (`WarnTrace`)
- [x] R3c: the go/defer number — **go, 34.3 %** — and the ruling in TODO §61.5
- [x] R3b: the `KnownFacts` door, the server's one implementation, the hash tie
- [x] R3b: proofs — fingerprint equality on a part-reused index, a stale
record refused, a misfiled record refused, the `(K − reused) + E`
formula, warm-store/no-store parity, unsaved-buffer precedence, and
an `#[ignore]`d 860-file corpus probe asked three ways
- [x] R3b: the paired measurement against `07ef771` — five of six gates met,
the wire-time percentage missed at −17.4 % (the absolute ≤ 318 ms form
met at 314.0), with the remaining stage named and measured
- [x] the collateral decision for the other refactorings — **not taken**,
measured as nil, and why
- [x] QA — PASS (2026-09-09, see QA log)
## Work log
**2026-09-08 (dev).**
- Read §61 header, §61.5, the review's §3 and its Gate, the tracker's R3b/R3c
rows, and `perf5-p2`, `perf5r-preflight`, `index-persistence`,
`workspace-index`, `refactor-rename`, `topo.md` §1.2/§3.
- Built the reference binary from the clean tree at `07ef771` **before any
edit** and preserved it (`lucisv-server-head`,
`50d8315a738103f006a28e1f6ea46c476a776fff1d880b860fc1bbcd83b315e9`).
- **R3c first.** Added `IndexTrace` and `WarnTrace` to `vlog_refactor`'s
trace, threaded through `Scope::build_keeping` and `Scope::warnings`. Both
are out parameters filled as the build runs, in the shape `RenameTrace`
already had, and both print as their own `name{…}` group so the existing
`phases_p2.parse_trace` flattens them into `trace_index_*` /
`trace_warnings_*` row fields with no harness change. The classification
(`text.contains(word)`) moved from after the analysis to before it — the
same pure question of the same two values — so the class can decide which
stage the analysis is billed to, and (later) whether it happens at all.
- Collapsed rather than kept the untraced wrappers: `build_keeping` and
`warnings` take the trace, because a wrapper nothing called was dead code.
- The intra-analysis split needed instrumentation inside
`vlog_semantic::workspace::record::analyzed_facts`, which this lane may not
change. Measured it instead in a **trace-only build** (§R1b's protocol): the
private body expanded over the public API in `Scope`, run once, numbers
recorded above, and the expansion removed before anything else was written.
The shipped trace has no intra-analysis fields.
- Ran `renametrace` at that build. **Go: 83.1 / 242.4 = 34.3 %.**
- **R3b.** `KnownFacts` in `scope.rs`, `Building` (the build in progress) so
`assemble` stays readable at one screen, `rename_traced_with` beside
`rename_traced` with one shared body, `IndexCache::entry_for` +
`facts_now`, `Workspace::known_facts`, and `rename.rs::Known`.
- `facts_now` exists rather than reusing `facts_for` because `facts_for`
counts its work into `IndexCache::work`, which `ScanTrace` subtracts per
scan: a rename decoding 238 records between two scans would otherwise
appear in the next scan's trace as decodes it never made. Both go through
`entry_for`, so the content tie is still one function.
- Proofs written before the measurement, all green:
`an_index_part_reused_and_part_parsed_is_the_index_the_texts_build`
(fingerprint + file ids + per-file analyses, two of four records reused),
`a_caller_that_knows_nothing_builds_exactly_what_it_always_did`,
`a_reused_record_removes_that_files_parse_and_changes_no_edit`
(`(K − 3) + E`, every stage's parse count, edits and warnings identical),
`a_file_whose_analysis_is_read_is_still_parsed_when_its_record_is_known`,
`a_record_that_names_another_file_is_not_taken`,
`a_request_local_read_answers_for_these_bytes_and_counts_as_no_scan_work`
(the stale record refused four ways, and the scan counters untouched),
`a_rename_over_a_warm_store_says_exactly_what_one_with_no_store_says`
(server level: same edits, same warnings, `parses{index=2}` against 3),
`an_unsaved_buffer_is_parsed_and_renamed_from_its_own_text`, and the
`#[ignore]`d `a_corpus_rename_says_the_same_thing_however_many_records_are_reused`
over the repo's 860-file corpus (run it with
`tools/guard.sh -m 8 -t 1200 -- cargo test -p vlog_refactor --test corpus -- --ignored --nocapture`;
it prints its own parse counts).
- `cargo test --workspace` **4 374 passed, 0 failed** (4 366 at the start of
the lane, +8 and none removed); `cargo fmt` clean; guarded
`cargo clippy --all-targets --workspace` clean with no new `#[allow]`.
**2026-09-08 (dev), the measurement and what it cost.**
- Six phases, each run twice per binary with the order alternated, then the
`renamewarn` phase once per binary. Numbers in "The R3b measurement" above;
raw evidence and a reproduction recipe in `~/.cache/lucisv-perf/take5r-5/`.
- `renamewarn` is new (`tools/perf/phases_r3b.py`) and exists because a hole
was found while planning the parity proof: `schema.fingerprint` can carry
warnings, but `phases_p2` calls it as `fingerprint(edit)` — and a rename's
warnings never travel in the `WorkspaceEdit` at all, they are
`window/logMessage` notifications. So no existing phase would have caught a
reuse that kept every edit and dropped a sentence. It dumps them verbatim
and they are compared line by line, not hashed.
- The gate was measured, missed by 2.6 points, and reported as missed. The
≥ 20 % is against this session's paired HEAD (380.2 ms); against the
review's own 398.3 ms baseline the same 314.0 ms is −21.2 %, and the
brief's absolute restatement of the gate (≤ 318 ms) is met. Closing the
2.6 points is available and was **refused**: it means taking the decoded
record from `WorkspaceIndex` and only the hash from the cache, and a record
filed under a path is not evidence about the bytes a rename was handed.
**Deviations from the lane's stated file list, all flagged rather than silent:**
- `crates/vlog_refactor/src/rename/warnings.rs` (+33) is not in the list, and
the lane's own instruction to split the `warnings` stage into its scans
cannot be carried out without it. `Scope::warnings` has exactly one
production caller, so the change is the trace parameter and nothing else.
- `crates/vlog_refactor/src/rename/tests.rs` and `tests/corpus.rs` — test
files for the module the lane owns; `crates/vlog_refactor/tests/*` is in the
list and `src/rename/tests.rs` is the same crate's unit tests.
- `crates/lucisv_server/src/state/mod.rs` gains **4 production lines** (a
`&self` query and its doc comment), taking it 974 → 978. It is already the
file TODO §55 is filed against, and the query must sit beside the private
`cache` field it reads; moving one `&self` call into a new module would be
worse than the four lines. Flagged for the lead.
- `tools/perf/phases_r3b.py` (new), plus its one-line registration in
`bench.py` and two rows in `tools/perf/README.md` — `tools/perf/` is in the
list.
- **Not mine:** `docs/perf/README.md` acquired a §61 round entry during this
session (the lead's, §61.6). It was left untouched; the working tree was
clean at `07ef771` when this lane started.
## QA log
**2026-09-09 (QA, Sonnet).** Verified in the main tree unless noted; code
attacks in a fresh clone at `07ef771` with the working-tree diff applied
(`/private/tmp/.../scratchpad/qa-61-5/clone`), never in the main tree.
Verdict: **PASS**.
**1. Gates.** `cargo fmt --all -- --check` clean. `cargo clippy --all-targets
--workspace` clean, no new `#[allow]` (grepped every touched file). `cargo
test --workspace` (guarded, release): **4 374 passed, 0 failed, 45 ignored**
— matches the dev's claim exactly. Re-ran `vlog_refactor` + `lucisv_server`
alone in the isolated clone: 2 265 passed, 0 failed (then 2 268 after my own
3 added tests, still 0 failed). `git diff --stat crates/vlog_refactor/src/check/`
is empty. Production line counts (non-blank, non-comment, before the inline
`mod tests {}` or the external `mod tests;` declaration): `scope.rs` 176,
`rename/mod.rs` 423, `warnings.rs` 441, `trace.rs` 132, `index_cache.rs` 343,
`state/mod.rs` 979 (dev says 974→978; 1-line off on my boundary heuristic,
not a real discrepancy). All comfortably under the 600-line mark; nothing
crosses a threshold.
**2. THE TIE.** Read `IndexCache::entry_for`/`facts_now`/`facts_for`
(`crates/lucisv_server/src/index_cache.rs`), `Workspace::known_facts`
(`state/mod.rs:489`) and `rename.rs::Known`. Confirmed: `entry_for` is the
**one** place a record and its FNV-1a are compared (`self.entries.get(path)
.filter(|e| e.content == content_hash(text.as_bytes()))`); `facts_now` and
`facts_for` both go through it, differing only in whether `IndexCache::work`
is charged; `known_facts` is one line to `self.cache.facts_now(path, text)`
— the workspace index (`self.index`) is never consulted. `Known` is a
newtype whose whole body is `Workspace::known_facts`.
Attacks, all in the clone:
- **(a) stale-disk-after-scan** — new test
`index_cache::tests::a_file_edited_on_disk_after_the_scan_misses_the_stale_record`:
record a file, edit it on disk with no watcher event, confirm `facts_now`
misses for the new bytes and still answers for the old ones. Passes.
- **(b) tampered store line** — read the existing (pre-existing, not
R3b/R3c's) tests `a_record_whose_facts_do_not_match_their_checksum_is_dropped`
and the "accepted residue" test right after it. The store line is
`content_hash\tfacts\tchecksum(facts)`; a hand-edited line whose facts no
longer match its *original* checksum is dropped at load, never served. But
a forger who recomputes the checksum over the corrupted facts (keeping the
same content hash) **is** served — documented in the code as deliberate:
"the checksum is an accident detector, not a MAC... a forger recomputes the
checksum." This is a pre-existing property of the index store
(`docs/features/index-persistence/README.md`), untouched by this lane's
diff (`entry_for`/`facts_now` add no new logic here, they only add a second
*reader* of the same decode path `facts_for` already used). It is reachable
only by hand-editing the on-disk store file — not through any code path the
product itself writes through (`IndexCache::record` always writes a
checksum over the facts it actually encoded) — matching the review's
"immutable cached facts" premise. Not a §61.5 finding; not rework.
- **(c) unsaved buffer** — existing test
`rename::tests::an_unsaved_buffer_is_parsed_and_renamed_from_its_own_text`
(lucisv_server), run and green: a buffer whose text disagrees with disk
misses the store (content key) and is parsed from the buffer's own text.
- **(d) known record for an unselected path** — by construction: `take()`
only calls `known.facts_for(path, text)` once per file already in the
selected set, with that file's own path/text. A `KnownFacts` impl can
return facts for a path the rename never asks about; nothing would ever
call it, so there is nothing to ignore — verified by code reading, not a
runtime scenario.
- **(e) two files, identical content, different paths** — new test
`index_cache::tests::two_files_with_identical_text_never_cross_their_records`:
records both, confirms each is served its own `FileFacts::path()`, then
updates one file's record content and confirms the other file's record for
its original bytes is untouched and never answers for the sibling's new
text. Passes. (Structurally guaranteed too: `IndexCache::entries` is
`HashMap<PathBuf, Entry>` — path first, content second — so a content
collision alone can never reach the wrong path's entry.)
- **(f) kept files still parsed** — confirmed by code reading (`Building::take`:
a `Kept`/`Lead` file with a known record still runs
`analyze(&parse_source_tolerant(text).0, text)` to produce the `Semantics`
a later stage reads; only the record read-off is skipped) and by the
existing `lucisv_server` test
`a_rename_over_a_warm_store_says_exactly_what_one_with_no_store_says`,
which asserts `reused_files=3` but `parses{index=2` for its 3-file scope
(bystander.sv is the one skipped).
- **(g) sabotage.**
1. `entry_for` with the hash filter removed (`self.entries.get(path)` and
nothing else) → `index_cache::tests::a_request_local_read_answers_for_these_bytes_and_counts_as_no_scan_work`
fails immediately ("a stale record must not be served"), and
`rename::tests::an_unsaved_buffer_is_parsed_and_renamed_from_its_own_text`
fails too (reused_files=2 instead of 1 — the stale on-disk record for
the unsaved buffer's path gets served).
2. `Workspace::known_facts` redirected to `self.index.facts_for(path)
.cloned()` (the workspace index's own per-file record, which
`WorkspaceIndex` does hold but with no content hash beside it) →
**both** `an_unsaved_buffer_is_parsed_and_renamed_from_its_own_text` and
`a_rename_over_a_warm_store_says_exactly_what_one_with_no_store_says`
fail. Both sabotage variants restored afterward; re-ran the full
`vlog_refactor`+`lucisv_server` suite clean (2 268/0) to confirm no
residue.
**3. Index equality.** Existing test
`an_index_part_reused_and_part_parsed_is_the_index_the_texts_build` checks
fingerprint + file ids + per-file analysis print. Added
`scope::tests::a_part_reused_index_answers_defines_and_reexport_queries_like_the_texts_build`
(clone): a 4-file fixture with a `` `define`` table (a container file,
reused) and a package re-export (`export b_pkg::*;`, also reused), lead file
renaming a package member. Checked, mixed (part-reused) index vs a plain
`WorkspaceIndex::build` on the same texts: fingerprint equal;
`defines(file_id)` entry count equal; `member("b_pkg","SIG")` equal (found
the right query — `units()` is file-scope names only, a package `localparam`
is a *member*, not a unit; my first draft used the wrong query and caught
itself); `references_to` count on that declaration equal; `members_of_chain("a_pkg")`
(the re-export edge) equal; `hierarchical_declarations("SIG")` equal (empty
both sides, path exercised). Also ran the existing `#[ignore]`d
860-file corpus probe (`cargo test --release -p vlog_refactor --test corpus
-- --ignored --nocapture`, guarded): reproduces the dev's parse counts
exactly (**865 → 16 → 439**) and identical edits/warnings all three ways;
absolute timings differ from the dev's (this machine's load), which is
expected and not a finding.
**4. The verifier.** `check/` has zero diff (`git diff --stat
crates/vlog_refactor/src/check/` empty) and every test under it passed
unmodified as part of the full-workspace run. Sabotage: re-added a spurious
parse for a reused `Other`-class file in `Building::take` (an extra
`parse_source_tolerant(text)` billed to the same stage) →
`rename::tests::a_reused_record_removes_that_files_parse_and_changes_no_edit`
fails immediately (`left: 10, right: 7` against the asserted `(K-3)+E`
formula). Restored; re-verified green.
**5/6. Parity and re-measurement.** Independently re-derived from the raw
evidence in `~/.cache/lucisv-perf/take5r-5/` (not just read as prose):
- `r3c-results.jsonl`: tail row `trace_index_other=83.1`,
`trace_index=242.4` → 83.1/242.4 = **34.3 %** exactly, matching the go
ruling.
- `paired.jsonl`: 36 distinct (phase,row) keys, 0 mismatches on
fingerprint/message/status/result_count/edits/files/created/titles across
every head↔candidate pairing (144 compared pairs with the alternated-order
duplicates) — matches "36 rows, 0 mismatches" exactly. Re-derived the tail
rename's own median-of-medians: head 382.0 ms, candidate 316.0 ms
(**−17.3 %**), against the dev's 380.2→314.0 (−17.4 %) — same conclusion,
small difference from a different (but reasonable) medians-of-medians
convention.
- `warn.jsonl`: 8 rows (4 renames × 2 labels), sentence counts 434/12/0/1304
= **1 750** exactly; compared head vs candidate title-lists field by
field, byte-for-byte — **0 mismatches** across all four rows.
- `head.sha256` vs the actual preserved binaries
(`.../scratchpad/perf5r-5/bin/lucisv-server-{head,r3b}`): sha256 matches
exactly (`50d8315a...` / `a041b5f3...`), so I did not need to rebuild.
- **QA's own three renames**, run directly against the real opentitan tree
(3 975 `.sv`/`.svh` files) through `vlog_refactor::rename_traced` /
`rename_traced_with` (bypassing the LSP wire — this exercises exactly the
engine-level contract §61.5 owns), each asked three ways (no records,
every record, half): (i) `WidthPRDSBox`, a package parameter used bare via
`module aes_sbox import aes_pkg::*;` in `aes_sbox.sv`; (ii) `entropy_masking_req`,
a net declared in `aes.sv` and threaded into a `bind aes ...` connection in
`aes_bind.sv`; (iii) `seed_en`, declared in `aes_prng_clearing.sv` and
reached two hierarchy levels up as `u_aes_core.u_aes_prng_clearing.seed_en`
from `aes_bind.sv`. **All three: byte-identical edits+warnings across all
three reuse modes** (parses collapsed from ~3975 to single digits/dozens
with full reuse, reused_files 3975/1988 as expected). One side observation,
not a §61.5 finding: for (ii) and (iii), `aes_bind.sv`'s own occurrence is
neither edited nor warned about, identically in all three reuse modes —
reproduces at HEAD, so it's a pre-existing bind/hierarchy-resolution
question, not a reuse-safety one. Flagged as a background task
(`task_834abda3`) for separate investigation; not blocking this verdict.
**7. Traceability.** Re-derived (not merely read) the go-condition
arithmetic, the 36-row parity count, the 1 750-sentence count, the corpus
probe's 865/16/439 parses, and the tail rename's percentage — all matched
the README/tracker's numbers (see §5/6 above). `docs/perf/take5-tracking.md`'s
R3b/R3c experiment records cross-checked against the feature README: no
discrepancies found in either direction.
**8. `docs/perf/README.md`.** `git diff docs/perf/README.md` shows only the
appended "2026-09-08 — the review round (TODO §61)" section (34 new lines,
0 removed, nothing above it touched) — the lead's, per TODO §61.6. Not
edited.
**Opentitan / guard / hygiene.** `git -C opentitan status --porcelain`
checked repeatedly through this session: always exactly the three known
files (`hw/ip/aes/dv/tb/tb.sv`, `hw/top_darjeeling/.../ast.sv`,
`hw/top_earlgrey/.../ast.sv`) — my opentitan reads were read-only. Every
`cargo test`/`clippy` and the two release-mode ignored-test runs went through
`tools/guard.sh -m 8 -t ≤1200`; no guard kill. No `sleep` over 60 s; used
`Monitor`/background-PID waits instead. No lingering background processes at
session end (checked `ps aux` for `guard.sh`/`cargo`). All code experiments
and new tests live only in
`/private/tmp/.../scratchpad/qa-61-5/clone` (a disposable clone) — the main
tree's working-tree diff is untouched by QA except this README's QA log and
the TODO.md tick below.
**Small fixes:** none needed in the dev's diff itself — the only fix made
was to my own added test in the clone (a `cargo fmt` alignment nit and an
`assert_eq!(_, true)` → `assert!` clippy nit), both in throwaway QA code, not
in the feature's diff.
**Topo row for the lead:** confirm at merge —
`lucisv_server ──▶ vlog_refactor`, edge `rename_traced_with` + `KnownFacts`,
additive, no existing edge amended (`vlog_semantic` unchanged, `check/`
untouched).
## Review
**2026-09-09 (lead).** Accepted. Read `KnownFacts`, `entry_for`,
`facts_now`, `Workspace::known_facts`, the `Scope::assemble` branch, the
trace split, both logs and the tracker records; QA's sabotage of the tie
(hash stripped; the workspace index's record substituted) and its three
opentitan renames in three reuse modes are the acceptance.
- The split answered the review's question before anything was built —
the scope stage is the parser (lex 34 %, parse 32 %), and a third of it
is spent on files the rename never analyses — and the go condition I
wrote into the brief was met with a number (34.3 %).
- The design trusts exactly what the index already trusts and nothing
more: a record is reused only when the handed bytes hash to what that
store entry was written for, the record and the hash read from one
place, the workspace index's record never (it carries no hash). An
unsaved buffer can never hit; a file edited on disk without a watcher
event cannot hit. `check/` has no diff.
- Gates: tail rename 380 → 314 ms (−17 % against HEAD, −21 % against the
review's own baseline, which is how the review stated its gate; the
brief's absolute ≤ 318 met), the duplicate-module refusal 2.05 s →
0.7 s, `clk_i` −17 %, RSS lower, 36 rows and 1 750 warning sentences
byte-identical. The residue is named: 31 ms of store decode, the price
of the one-place tie, which I would not trade for a two-place one.
- Collateral to the other refactorings was measured nil and left with
the note that the resolves and the extract edit are the candidates,
since the 805 ms refusal is after the scope build.
- QA's side finding — a `bind` file's own occurrence of a renamed name
is neither edited nor warned, identically at HEAD — is pre-existing and
goes to the loop-3 list with QA's task reference.
Docs applied at merge: topo (`rename_traced_with` + `KnownFacts`); the
loop-3 note.
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->