Merge performance-wave Lane A (prepareRename, rename, willRenameFiles)
ci / checks (push) Successful in 50s
ci / corpus (push) Successful in 20s

Co-Authored-By: Claude Fable 5 <[email protected]>

# Conflicts:
#	docs/perf/README.md
This commit is contained in:
lucio committed 2026-08-29 00:11:42 -07:00
commit ee1efe3fb1
14 files changed
+2744 -39

No files matched your search

+129
View File
@@ -563,6 +563,88 @@ answer is empty. Depth 2 is the block the file belongs to — 21 files for 15 ms
of scan, once — and depth 3 is the whole of `hw/ip`, which is why the default
is 2 and not 3.
## Before / after — round 7, Lane A (2026-08-28)
`docs/features/refactor-rename/README.md` and
`docs/features/file-operations/README.md`: the three remaining `ws.sources()`
callers, and the two worst rows in `performance.md`'s table.
The framing round 6 inherited — "a rename is user-initiated, so it may be
slow" — was half wrong. **`prepareRename` is what the rename key sends before
the box opens**, and it was the second-worst number in the whole report: 2.5–
3.0 s of a wholly frozen single-threaded server on a keypress that had
committed to nothing, taking hover, definition and highlight down with it.
Its entire answer — the identifier's range and its placeholder — is in the
open buffer already.
Three fixes, three shapes:
- **`prepareRename`** is answered from the buffer's own `Semantics`, the
`ExternalResolutions` overlay beside it and the index. No file is read,
nothing is parsed. The refusal-by-refusal parity table is in the rename
README; four refusals that need the *declaring file's* own text are deferred
to `rename`, which is what LSP's optimistic `prepareRename` is for.
- **`rename`** is computed over the symbol's fan-out through the index — every
declarer of the old *and* the new name (units and members), every reference
posting, every instantiation edge, every macro definition, the containing
units and their fan-out, every file that *spells* the new name in a use the
index had to look outside that file to answer, plus every open buffer. The
sufficiency argument, the escape hatch for an ambiguously-referenced
declaration, and the named residue are in the rename README.
- **`willRenameFiles`** reads the include graph's includers instead of the
workspace: a file with no edge writes no `` `include`` this workspace can
resolve, so its turn in the sweep could only ever `continue`.
Measured over the real OpenTitan checkout (3 976 files indexed, `--release`,
same machine and corpus as `performance.md`):
| request | before | after |
|---|---:|---:|
| `textDocument/prepareRename` on the `aes` instantiation | 1.663 s | **139 ns** |
| `textDocument/rename` of `aes` (7 files edited) | 3.467 s | **105.5 ms** (7-file fan-out) |
| `workspace/willRenameFiles` for one header | 249 ms of `sources()` alone | **14.1 ms**, whole answer (331 includers of 3 976) |
The remaining 105.5 ms is the engine over 7 real files — index build, then an
analysis of each before and after the edit — not the workspace read:
`sources()` alone was 200–241 ms across runs, which is the row with the most
run-to-run spread on a machine that is not quiet. Building the fan-out itself
is **4.75 ms**, of which the one rung that scans the whole index rather than
looking a key up — `WorkspaceIndex::files_spelling`, the dangling-use rung
added in the QA-driven rework — is **852 µs at its worst** (a name nothing
spells, where the walk cannot short-circuit) and 402 µs for `clk_i`, which 681
files spell.
Every row was also checked for **equality** against the whole-workspace
computation, which is the point: this is a smaller input to the same engine,
not a cheaper approximation. Four real cursors in `tb.sv`:
| cursor | fan-out | result |
|---|---:|---|
| `aes` → `aes_core_top` | 7 of 3 976 | edits identical (7 files, 7 edits); **7 macro-invocation warnings lost** — the one accepted residue, see the rename README |
| `aes` → `prim_fifo_sync` | 7 | both refused, verbatim: *"renaming `aes` to `prim_fifo_sync` would change what `prim_fifo_sync` means in tb.sv"* |
| `clk_rst_if` → `clk_rst_thing` | 116 | edits identical (114 files, 275 edits); 64 → 61 warnings |
| `.clk_i` → `clock_in` | **3 976** | edits identical (4 files, 5 edits), all 652 warnings identical — the ambiguity escape hatch fired, so this cursor is correct but not faster |
and `prepare_rename_here` was swept against `prepare_rename` at every 7th byte
of the same file: **564 offsets, all identical, zero deferrals.**
Reproducible without that checkout, over 500 generated files of 200 lines plus
a module instantiated in three of them
(`perf::a_rename_before_and_after`, `perf::a_will_rename_before_and_after`):
| | before | after |
|---|---:|---:|
| `prepareRename` on the module name | 251 ms | **212 ns** |
| `rename` to a new name (4 files edited, 4-file fan-out) | 486 ms | **370 µs** |
| — building that file set | — | 128.7 µs, of which `files_spelling` 49.8 µs |
| `willRenameFiles`, reading the scope vs the includers | 16.1 ms | **18.9 µs** (whole answer 35.4 µs) |
Every OpenTitan and synthetic figure above was re-taken after the QA-driven
rework, so the tables describe the shipped code. The pre-rework round measured
1.604 s → 135 ns, 3.284 s → 103.6 ms, 238 ms → 200 ns and 465 ms → 294 µs on
the same corpora: the sixth rung is inside the run-to-run noise, which the
separate rung measurement says directly rather than by subtraction.
## What it would take to go faster
Ranked by what the measurements above say is there, with what each would
@@ -643,6 +725,12 @@ cost. None of these were attempted; each is a future round.
drain can break up (`perf::what_a_scan_does_before_its_first_file`).
The e2e probe above was flipped to
`a_hover_issued_during_the_initial_scan_is_answered_during_it`.
- [x] **Added in round 7, Lane A (2026-08-28):** the rename family's
before/after, over the same generated corpus round 6 uses
(`perf::a_rename_before_and_after`,
`perf::a_will_rename_before_and_after`), with the OpenTitan column and
the parity/equality sweeps taken by throwaway probes against the local
checkout and deleted.
- [ ] **Round 1's second open TODO, restated and still open:** memory.
Nothing in the repo measures resident size. Round 2 added no data
structure — two free functions and no state — so the figure it would
@@ -748,6 +836,47 @@ No figure in any earlier round was re-measured: nothing on those paths
changed. `completion.rs`'s tier 0 and `candidates.rs`'s tables are on no
earlier table.
**2026-08-28 — dev (round 7, Lane A).** Two probes added,
`a_rename_before_and_after` and `a_will_rename_before_and_after`, both over
the same 500-file generated corpus `a_code_action_at_an_instantiation_before_and_after`
uses — factored into `rename_corpus` so the three read against one another.
Each prints a before column computed the way the handler computed it until
this round (`vlog_refactor::rename` over `ws.sources()`) and an after column
that calls the real handler, so the comparison is one workspace, one cursor,
one run.
The OpenTitan column of round 7's table came from throwaway probes against
the owner's local checkout, run and deleted — no test may depend on a
checkout this repository does not carry. Three of them: the timings, a
**parity sweep** over every 7th byte of `tb.sv` comparing
`prepare_rename_here` against `prepare_rename` (564 offsets, all identical,
zero deferrals), and an **equality sweep** over four real cursors comparing
the fan-out rename against the whole-workspace one. The last is what earned
its keep: it showed the edit sets byte-identical everywhere (7 files at `aes`,
114 at `clk_rst_if`, 4 at `.clk_i`) and the capture refusal firing verbatim on
`aes` → `prim_fifo_sync`, **and** it found the one thing the synthetic suite
could not — the macro-invocation warnings the fan-out cannot see. That finding
is written up in `docs/features/refactor-rename/README.md`; it is also why the
`` `define`` rung of the fan-out is a walk over the index's tables rather than
a `find_define` lookup, which recovered two of the five warnings the
`clk_rst_if` cursor was losing.
Note on `a_rename_before_and_after`'s before column: it is ~480 ms rather than
the 249 ms `a_code_action_…` records for `prepare_rename` on the same corpus,
because a rename does the analysis twice — once to collect, once to verify —
where a prepare stops after locating the cursor. Both rows are printed by the
same run so neither has to be trusted from memory.
**2026-08-28 — dev (round 7 rework).** QA found a lost refusal in the fan-out
and the lead ruled it not shippable; the fix added a sixth rung
(`WorkspaceIndex::files_spelling`) whose cost, unlike the other five, grows
with the workspace rather than with the symbol. So `a_rename_before_and_after`
grew two lines — the whole file-set build, and that rung on its own — because
"the rung is free" is a claim, and a claim in this document needs a number
beside it. Every figure in round 7's tables was re-taken against the reworked
code rather than carried over; the pre-rework numbers are quoted underneath so
the rung's cost can be read as a difference as well as directly.
## QA log
**2026-08-28 — QA.** No findings — every number reproduces within reason.