Take 2 filed the RTL didOpen freeze as a chooser bug; measuring with the HEAD binary refuted that — scope_dirs keeps every raised dir so subsumption is Added, and begin_widen has file-diffed against the index since the widen round; the 1.4-1.7 s figures were cold-store. The real cost was candidates.absorb inserting each new word into the sorted table one memmove at a time — quadratic in the batch, 403 ms of a 935 ms warm jump — replaced by a counted one-pass merge whose equivalence with build's sort is structural (43 ms). Warm hw/ip jump 935/881 -> 555/564 ms (QA: 872-880 -> 535-546 from its own builds); the residual is real work, 1 683 new files and a 325 ms word re-lex filed as the store's FACTS_FORMAT follow-up. The two previously accidental properties are now pinned, QA's five-mutation matrix confirming each test binds exactly its property. TODO.md carries take 2's other findings (codeAction big-fan-out zero-offers, inlayHint at default scope) as deferred items. Co-Authored-By: Claude Fable 5 <[email protected]>
1050 lines
57 KiB
Markdown
1050 lines
57 KiB
Markdown
# perf — measured numbers for the paths a keystroke and a hover run through
|
||
|
||
## Goal
|
||
|
||
Give the server's hot paths — `analyze`, opening a buffer, answering a hover,
|
||
reindexing one saved file, and (since round 2) one flush stage by stage and
|
||
one keystroke's round trip over the wire — a number that is *measured* rather
|
||
than guessed, taken the same way every time, so a later round can say whether
|
||
it made something faster or only different. This is the record; the
|
||
measurements themselves are `#[ignore]`d tests in
|
||
`crates/lucisv_server/src/perf.rs` and in
|
||
`crates/lucisv_server/tests/e2e.rs`, run on demand and asserting nothing about
|
||
duration. Nothing here is a performance *budget*: a test that fails when a
|
||
machine is busy is a test that gets deleted.
|
||
|
||
## Assumptions
|
||
|
||
- **No benchmark dependency.** `criterion` and friends are out: `CLAUDE.md`
|
||
requires a written justification for any new dependency, and the workspace
|
||
has six direct ones (`rayon`, `lsp-server`, `lsp-types`, `serde`,
|
||
`serde_json`, plus their pins). `std::time::Instant` + `eprintln!` is the
|
||
shape this repo already uses for perf notes (`hover.rs`'s QA measurement,
|
||
`includes.rs`, `inlay.rs`, `file_ops.rs`) and it is what is used here.
|
||
- **`--test-threads=1` or the numbers are noise.** The harness otherwise runs
|
||
these concurrently with each other and with 1 200 other tests. The first run
|
||
of these measurements was taken without it and reported a cross-file hover
|
||
as *cheaper* than the single file read it performs; that is how obvious the
|
||
contamination is.
|
||
- **Means, not single runs.** Each measurement is the mean of 10–1 000 runs
|
||
(`perf::mean`), with `std::hint::black_box` around the inputs and results so
|
||
a release build cannot optimize the work away.
|
||
- **Generated input, not the corpus.** `perf::generated_module` builds an
|
||
ANSI-headed module of repeated four-line blocks (a wire, an assign, a
|
||
register, an update) at 1 000 and 10 000 lines. It is uniform, which real
|
||
RTL is not — the numbers are a scale, not a prediction for any given file.
|
||
The corpus-scale numbers this repo already has live where they were taken
|
||
(`docs/features/incremental-index`, `index-persistence`, `references-nav`).
|
||
|
||
## Reproducing
|
||
|
||
```text
|
||
cargo test --release -p lucisv_server perf:: -- --ignored --nocapture --test-threads=1
|
||
```
|
||
|
||
Each test's own doc comment names the narrower filter for running it alone.
|
||
The over-the-wire measurement lives with the other end-to-end tests, because
|
||
it spawns the shipped binary, so it has its own command:
|
||
|
||
```text
|
||
cargo test --release -p lucisv_server --test e2e a_keystroke -- --ignored --nocapture --test-threads=1
|
||
```
|
||
|
||
The one older measurement quoted below has a third:
|
||
|
||
```text
|
||
cargo test --release -p lucisv_server large_closed -- --ignored --nocapture --test-threads=1
|
||
```
|
||
|
||
## The machine
|
||
|
||
| | |
|
||
|---|---|
|
||
| CPU | Apple M1 Max (`uname -m` = `arm64`) |
|
||
| OS | macOS 27.0 (build 26A5421a) |
|
||
| build | `--release`, workspace at 0.12.1 + rounds 1 and 2 uncommitted |
|
||
| date | 2026-08-28 (every figure below re-measured this day, round 2) |
|
||
|
||
## Numbers
|
||
|
||
All figures are the mean of the runs named above. "1k" and "10k" are the
|
||
generated module's line counts (29 KB / 501 symbols and 309 KB / 5 001
|
||
symbols respectively).
|
||
|
||
| what | 1k lines | 10k lines |
|
||
|---|---|---|
|
||
| `vlog_semantic::analyze` (tree already parsed) | 252 µs | 3.76 ms |
|
||
| `Document::new` — lex + parse + analyze + `resolve_external` | 2.54 ms | 31.1 ms |
|
||
| `hover`, target declared in the same open buffer | 2.68 µs | 1.10 µs |
|
||
| `hover`, target in a **closed** file (disk path) | 38.1 µs | 159 µs |
|
||
| — of which one read + one `LineIndex` of that file | 27.4 µs | 140 µs |
|
||
| `WorkspaceIndex::update_file`, 20 files of this size | 2.76 ms | 32.1 ms |
|
||
| — of which the clone the measurement needs to repeat itself | 60 µs | 567 µs |
|
||
| one name looked up among the file's symbols: **linear scan** | 767 ns | 8.14 µs |
|
||
| one name looked up among the file's symbols: **name-sorted lookup** | 93 ns | 131 ns |
|
||
| one token found at the cursor: **sweep** | 6.58 µs | 77.5 µs |
|
||
| one token found at the cursor: **binary search** | 15 ns | 20 ns |
|
||
| the balanced-paren window `completion.rs` needs: **sweep** | 8.63 µs | 130 µs |
|
||
| the balanced-paren window `completion.rs` needs: **binary search** | 27 ns | 36 ns |
|
||
|
||
Every figure above comes from one run of the command in *Reproducing*, on the
|
||
machine above. A local hover is a handful of pointer chases and comes out
|
||
under 3 µs at both sizes; the 1k figure being the larger of the two is that
|
||
measurement's noise floor, not a result.
|
||
|
||
Three things stand out:
|
||
|
||
- **A hover into a closed file is a file read.** 27 µs of the 1k hover's
|
||
38 µs, and 140 µs of the 10k hover's 159 µs, is reading that file and
|
||
building a `LineIndex` over it. Everything else — resolution, guards,
|
||
rendering — is single-digit microseconds.
|
||
- **`Document::new` is where a keystroke's cost lives**, and it is dominated
|
||
by lexing and parsing, not by `analyze` (31 ms against 3.8 ms at 10k
|
||
lines). The stage-by-stage table below says exactly how much.
|
||
- **A sweep of the token vector costs about what the parse of one line
|
||
costs**, and there are several per keystroke. That is round 2's Phase 2.
|
||
|
||
### One flush, stage by stage
|
||
|
||
`Document::new` runs the first seven of these in order; the eighth is not
|
||
inside it at all — `diagnostics::all` is what a *publish* runs, on every
|
||
flush, and round 1's table did not account for it.
|
||
|
||
`parse_tolerant` consumes its token vector, so each run of the parse needs a
|
||
fresh clone. The clone has its own row and the parse row still contains it;
|
||
subtracting one from the other is the honest reading, and it is what
|
||
`Document::new` really pays.
|
||
|
||
| stage of one flush | 1k lines (9 461 tokens) | 10k lines (94 961 tokens) |
|
||
|---|---|---|
|
||
| `tokenize` | 1.14 ms | 12.5 ms |
|
||
| `tokens.clone()` (the copy `Document` keeps) | 230 µs | 2.40 ms |
|
||
| `parse_tolerant`, clone included | 1.16 ms | 14.3 ms |
|
||
| — the parse alone, by subtraction | 0.93 ms | 11.9 ms |
|
||
| `collect_defines` | 7.09 µs | 121 µs |
|
||
| `analyze` | 278 µs | 5.55 ms |
|
||
| `resolve_external` | 943 ns | 49.3 µs |
|
||
| `LineIndex::new` | 10.5 µs | 115 µs |
|
||
| `diagnostics::all` (parse errors + closers + lint) | 104 µs | 1.40 ms |
|
||
|
||
Read this table as *shares of a flush*, not as the last word on any one
|
||
stage: it runs eight measurements back to back on one heap, and its `analyze`
|
||
row came out 5.55 ms in the same run where the dedicated `analyze` test —
|
||
which measures nothing else — came out 3.76 ms. The dedicated figure is the
|
||
cleaner one. What the table is for is the proportion, and the proportion is
|
||
unambiguous:
|
||
|
||
- **Lexing and parsing are 79 % of a flush** at 10 000 lines (12.5 + 11.9 of
|
||
30.9 ms, taking the dedicated `analyze` figure for the rest). Everything
|
||
else together is a fifth.
|
||
- **`tokens.clone()` is 7.7 %**, and it is load-bearing rather than waste:
|
||
`parse_tolerant` takes ownership of its tokens and *steals the comments out
|
||
of them*, so the copy `Document` keeps is the only one that still has its
|
||
trivia. It is also already the cheap option — before the one-lex change
|
||
this was a second `tokenize`, which is 12.5 ms.
|
||
- **`resolve_external` is 49 µs, one part in six hundred.** Making the
|
||
workspace overlay skippable was on this round's list of candidates; the
|
||
measurement says there is nothing there to save.
|
||
- **The lint pass is 1.40 ms on top of the flush**, about 4 %. It walks the
|
||
tree once per rule.
|
||
|
||
### Over the wire — what a keystroke actually costs a user
|
||
|
||
Round 1 listed this as its own open TODO, because it cannot be taken from
|
||
inside the crate: the number includes two pipes, a JSON encoder and decoder,
|
||
the change debounce's quiet-period timer and a whole flush. It is measured by
|
||
spawning the shipped binary and speaking framed JSON-RPC at it
|
||
(`tests/e2e.rs::a_keystroke_round_trip_over_the_wire`, command above).
|
||
|
||
| `didChange` → `publishDiagnostics` | 1k lines | 10k lines |
|
||
|---|---|---|
|
||
| one keystroke, nothing following it | 164 ms | 202 ms |
|
||
| a burst of ten keystrokes, no pause | 165 ms | 207 ms |
|
||
| — publishes that burst produced | **1** | **1** |
|
||
| one keystroke **a request follows** (mean of 10) | 4.35 ms | 37.6 ms |
|
||
|
||
The three rows say three different things.
|
||
|
||
- **The debounce is the felt latency when a client asks for nothing.**
|
||
150 ms of the 164 ms is `CHANGE_DEBOUNCE`'s quiet period; the work is the
|
||
rest. At 10 000 lines the same 150 ms sits on top of a 31 ms flush. This
|
||
is the one row where round 1 made something *slower*: before the debounce
|
||
a lone keystroke published in about one flush, and it now waits out the
|
||
timer first. It is the bargain debouncing is, and the last row is why it
|
||
is worth taking.
|
||
- **A real editor never waits for that timer.** VS Code asks for semantic
|
||
tokens, inlay hints and highlights the moment a buffer changes, and a
|
||
request flushes the dirty buffer before it is answered. That is the last
|
||
row, and it is the number a user actually feels: **4.35 ms at 1 000 lines,
|
||
37.6 ms at 10 000**.
|
||
- The first two rows are single round trips, not means, and each is bounded
|
||
below by a 150 ms timer; treat their differences as noise. The last row is
|
||
the mean of ten and is the one worth comparing across rounds.
|
||
|
||
## Before / after — round 1 (2026-08-28)
|
||
|
||
**A1 — didChange debounce.** Not measured directly *at the time*, and the
|
||
arithmetic below is what round 1 recorded: every `didChange` used to run one
|
||
`Document::new` plus lint and publish; a burst of *k* changes now runs one.
|
||
At 10k lines that is 31 ms saved per keystroke after the first in a burst, at
|
||
1k lines 2.6 ms. What the debounce cannot save is the first change in a burst
|
||
and the last flush, so the floor is one `Document::new` per burst per buffer.
|
||
|
||
**Round 2 measured it.** A burst of ten keystrokes over the wire produces
|
||
**one** `publishDiagnostics`, counted rather than reasoned about — the count
|
||
comes from draining the session at `shutdown`, which every pending flush is
|
||
guaranteed to have arrived before. The arithmetic above was right.
|
||
|
||
The burst is deliberately the **last** thing that measurement does, which is
|
||
QA finding IL-1 closed: every `wait_for` in the test accepts *any* publish,
|
||
so while the burst ran before the other rows, a second publish it had
|
||
produced would have been absorbed by the next row's wait and never counted.
|
||
With nothing between the burst and the drain, the count is the count.
|
||
|
||
**A2 — one disk read per hover.** Measured, two ways.
|
||
|
||
- The QA round that filed the finding measured a hover into a 31.7 MB closed
|
||
file at **34 ms** (`docs/features/hover-declarations/README.md`, finding 4,
|
||
2026-08-27, same machine, same test, release build). The same test after
|
||
the `disk_view` memo: **16.3 ms**. That is the expected shape — two reads
|
||
and two `LineIndex` builds became one — but the two numbers come from
|
||
different runs on different days, so read it as "about half", not as
|
||
2.08×.
|
||
- The `perf::hovering_across_files_into_a_closed_file` measurement takes the
|
||
after-number and the cost of one read + `LineIndex` side by side, in the
|
||
same run: 142 µs of a 160 µs hover at 10k lines. Removing a second read of
|
||
that same file is therefore removing roughly the whole remaining cost of
|
||
the request, which is the before/after in the form that does not depend on
|
||
an old number.
|
||
|
||
**A3 — name-keyed symbol lookup.** Measured directly, on the lookup alone:
|
||
8.41 µs → 133 ns at 10k lines (5 001 symbols), 763 ns → 106 ns at 1k. The
|
||
lookup is only part of what was saved: in `hover::live_symbol` every symbol
|
||
the scan used to reach was also an `indexed_def_for_symbol` call — two index
|
||
lookups apiece — which the name-sorted lookup never makes. That larger saving
|
||
is **not measured here**; the 8.41 µs → 133 ns figure is a floor on it, not
|
||
the whole of it.
|
||
|
||
**B — port detail spans, and comment attachment.** Not measured. The work
|
||
added is a second `fenced_sections` call over lines already in memory, and
|
||
two integers per declaration in the index and its facts records. No
|
||
measurement was taken and none is claimed.
|
||
|
||
## Before / after — round 2 (2026-08-28)
|
||
|
||
**C1 — six token lookups stopped sweeping the buffer.** Measured directly,
|
||
both halves in the same run against the same token stream
|
||
(`perf::finding_one_token_against_sweeping_the_stream`), with the cursor
|
||
three quarters of the way down the file — a sweep costs the distance from
|
||
token zero, so measuring at either end would flatter it.
|
||
|
||
| | 1k lines | 10k lines |
|
||
|---|---|---|
|
||
| the token at the cursor: sweep → binary search | 6.58 µs → 15 ns | 77.5 µs → 20 ns |
|
||
| `balanced`'s window: sweep → binary search | 8.63 µs → 27 ns | 130 µs → 36 ns |
|
||
|
||
Six call sites across `selection.rs`, `on_type.rs`, `completion.rs` and
|
||
`inline.rs`; which ones, what each of them wanted, and the per-site argument
|
||
that the search returns exactly what the sweep returned are in
|
||
`docs/features/interactive-latency/README.md`. Every one is pinned by a test
|
||
that walks **every byte** of a buffer full of touching tokens and compares
|
||
the two. None of them changed an answer, and the tests are what says so
|
||
rather than the claim.
|
||
|
||
Three sweeps were left alone with the reason written down: `signature.rs`'s
|
||
two paren-depth walks (a depth is a function of every bracket before the
|
||
cursor), `pairs.rs::analyze` (not a position query at all), and
|
||
`completion.rs`'s comment gate (comments are trivia attached to whichever
|
||
token happens to be next, so no search of the stream answers "is this byte
|
||
inside a comment"). That last one is the remaining per-keystroke
|
||
whole-buffer walk on the completion path.
|
||
|
||
**C2 — the round trip, and nothing else changed.** No stage of a flush was
|
||
touched this round, so the flush table above is a baseline rather than an
|
||
after. The reasons each candidate was refused, with its number, are in the
|
||
next section.
|
||
|
||
## Before / after — round 3 (2026-08-28)
|
||
|
||
`docs/features/hover-line-index/README.md` — the owner's report that hovering
|
||
an instantiation, and a port on that instantiation, is slow on the first try.
|
||
Two suspects were measured before anything was changed; the numbers said which
|
||
one this round could fix and which it could only file.
|
||
|
||
**D1 — the heading stopped reading the file, and the snippet's read is
|
||
shared.** Each indexed declaration now carries its line (`Def::lines`,
|
||
`FACTS_FORMAT` 3 → 4), so `file:line` costs nothing; the snippet still wants
|
||
that file's text, and takes it from a four-entry / 8 MiB LRU of closed files'
|
||
text in `Workspace`. So the *first* touch of a file still pays one read and
|
||
every touch after it pays nothing.
|
||
|
||
| | before | after |
|
||
|---|---:|---:|
|
||
| hover on an instantiation into a 12 MB closed file, first touch | 6.47 ms | 6.23 ms |
|
||
| — the same hover again | 5.75 ms | **0.95 µs** |
|
||
| hover on a port into the same file, first touch | 5.85 ms | 5.92 ms |
|
||
| — the same hover again | 5.71 ms | **0.99 µs** |
|
||
| the 31.7 MB probe above, first touch | 17.0 ms | 16.8 ms |
|
||
| — the same hover again | 17.0 ms | **4.4 µs** |
|
||
| `perf::hovering_across_files_into_a_closed_file`, 1k / 10k (mean of 20) | 39.8 / 157 µs | **4.7 / 12.9 µs** |
|
||
|
||
The cost, over the 860-file corpus: one `LineIndex::new` per parsed file, which
|
||
leaves every scan figure inside its own noise (no cache 338 → 343 ms, cold
|
||
372 → 374 ms, warm 197 → 200 ms), and 68 KB more store — 2.9 %.
|
||
|
||
**D2 — the first request of a session waits out the startup scan.
|
||
Measured, filed, not fixed.** `Server::new` runs the whole scan before the
|
||
message loop takes its first message, so anything a client sends the instant
|
||
the handshake finishes sits in the OS pipe until the scan ends. Over 200 files
|
||
of 1 000 lines, through the shipped binary
|
||
(`tests/e2e.rs::a_hover_issued_during_the_initial_scan_waits_for_it`):
|
||
|
||
| the first hover of a session | cold store | warm store |
|
||
|---|---:|---:|
|
||
| issued the moment `initialized` was sent | **780 ms** | **287 ms** |
|
||
| the same hover once the scan is done | 64 µs | 61 µs |
|
||
|
||
This is four orders of magnitude larger than D1 and is where "the first hover
|
||
is slow" mostly lives. Fixing it is a change to request scheduling — answering
|
||
while the index is half-built, or scanning off the message-loop thread — and
|
||
was explicitly out of this round's scope.
|
||
|
||
## Before / after — round 4 (2026-08-28)
|
||
|
||
`docs/features/scan-interleave/README.md`: D2, answered. The scan is per-file
|
||
steps with the message queue drained between them, so a startup scan of more
|
||
than 64 files answers requests while it runs — single-threaded, interleaved,
|
||
not scanned off-thread. Same fixture, same probe, flipped and renamed
|
||
(`tests/e2e.rs::a_hover_issued_during_the_initial_scan_is_answered_during_it`):
|
||
|
||
| the first hover of a session | before | after |
|
||
|---|---:|---:|
|
||
| issued the moment `initialized` was sent, cold store | **780 ms** | **15.5 ms** |
|
||
| — warm store | **287 ms** | **12.8 ms** |
|
||
| the same hover once the scan is done | 64 / 61 µs | 191 / 151 µs |
|
||
|
||
The "after" figures are tens of milliseconds, not three significant figures: a
|
||
second run on a busier machine reported 19.8 / 14.0 ms. The claim is the order
|
||
of magnitude, and the post-scan row is measured after waiting for the progress
|
||
bar rather than racing the scan.
|
||
|
||
**What it cost the scan: under a percent.** The merge was measured before the
|
||
design was chosen, and the numbers ruled out the obvious shape — a merge is a
|
||
pass over the whole index, so folding each file in as it is taken would be
|
||
quadratic (`perf::publishing_a_half_built_index_mid_scan`, 200 files of 1k
|
||
lines: 630 ms of merging against 464 ms of parsing; 800 files: 11.7 s against
|
||
1.78 s). Records are staged and folded in once per *drain* instead, and a drain
|
||
only happens when a message is waiting:
|
||
|
||
| 860-file corpus | before | after |
|
||
|---|---:|---:|
|
||
| no cache | 321.5 ms | 322.0 ms |
|
||
| cold, filling the store | 351.3 ms | 353.4 ms |
|
||
| warm, every file from the store | 187.0 ms | 188.6 ms |
|
||
|
||
The floor under the 15.5 ms is one block no drain can break up:
|
||
`perf::what_a_scan_does_before_its_first_file` puts **6.9 ms** before the first
|
||
file (resolve the scope, read all 200 files, open the store) against 4.0 ms for
|
||
one file — so reading the files lazily is what a single-digit number would take,
|
||
and it is filed as a deliberate not-done in that feature's README.
|
||
|
||
## Before / after — round 5 (2026-08-28)
|
||
|
||
`docs/features/index-scope/README.md`: the owner's opentitan report. Every F12
|
||
into a folder the scope had not reached ran a whole rescan of every folder
|
||
reached so far, and `must_wait` holds the next request behind it — so the wait
|
||
grew with the session. A widen now indexes the folders it added and folds them
|
||
in. Measured over the real checkout (3 979 SV files, warm store, folder scope,
|
||
`--release` over stdio, the `HEAD` binary and this one alternated in one
|
||
session), timing the `textDocument/definition` sent straight after each
|
||
`didOpen`:
|
||
|
||
| the next request after a jump | before | after |
|
||
|---|---:|---:|
|
||
| `didOpen hw/ip/aes/rtl` | 120 ms | **22 ms** |
|
||
| `didOpen hw/ip/kmac/rtl` | 132 ms | **18 ms** |
|
||
| `didOpen hw/ip/hmac/rtl` | 137 ms | **12 ms** |
|
||
| `didOpen hw/ip/spi_device/rtl` | 169 ms | **44 ms** |
|
||
| the session's first definition (waits for the first widen) | 99.7 ms | **0.9 ms** |
|
||
| a definition once the scope has settled | 0.06–0.11 ms | 0.05–0.06 ms |
|
||
|
||
**The shape is the claim, not the ratio.** What is left is proportional to the
|
||
folder being opened — `spi_device/rtl` is the big one and costs the most, every
|
||
time — and no longer to how long the user has been browsing. Two thirds of the
|
||
first row is not parsing at all: `begin_scan` re-opens the persistent store on
|
||
every whole rescan, and decoding 3 979 records is ~90 ms of it, which a widen
|
||
does not pay because it keeps the handle the last whole rescan left.
|
||
|
||
Reproducible without that checkout:
|
||
`perf::what_a_jump_into_a_new_folder_costs_before_and_after` generates 40
|
||
folders × 25 files of 200 lines and runs **both shapes over the same tree in
|
||
the same run**, asserting after every jump that the two indexes fingerprint
|
||
identically:
|
||
|
||
| jump | files in scope after it | whole rescan | incremental widen |
|
||
|---|---:|---:|---:|
|
||
| 0 | 25 | 18.2 ms | 17.8 ms |
|
||
| 1 | 50 | 37.1 ms | 18.1 ms |
|
||
| 3 | 100 | 71.7 ms | 18.7 ms |
|
||
| 5 | 150 | 107.1 ms | 19.2 ms |
|
||
|
||
The first row being equal is the honest baseline: with nothing indexed yet the
|
||
two paths do the same work.
|
||
|
||
**What it cost the whole scan: nothing measurable.** The include graph now
|
||
re-spells every held edge on each `relearn`, which is the one thing this round
|
||
added to a path a whole scan runs.
|
||
`state::tests::qa_perf_cold_warm_and_half_warm_scans`, 860-file corpus, after:
|
||
**361 / 381 / 202 ms** (no cache / cold / warm) against the 322 / 353 / 189 ms
|
||
recorded above and the 347 / 387 / 203 ms QA measured on a busier machine — the
|
||
same band, and the store is byte-identical at **2 380 790 bytes**, which is the
|
||
number machine load cannot move.
|
||
|
||
## Before / after — round 6 (2026-08-28)
|
||
|
||
`docs/features/refactor-ports/README.md`: the rest of the owner's "goto
|
||
definition is slow" report. The definition itself answered in microseconds —
|
||
it was queued behind `textDocument/codeAction`, which VS Code sends on nearly
|
||
every cursor move and which read the whole in-scope file set from disk and ran
|
||
the refactor engine over it whenever the cursor sat on an instantiation or a
|
||
port. The owner's instrumented session: **3 111 ms** and **3 014 ms** per code
|
||
action, against 0.01–0.44 ms for every other request. The file set is now the
|
||
cursor's module's own fan-out through the index — definers, instantiation
|
||
edges, reference postings, open buffers — instead of the workspace.
|
||
|
||
Measured over the real checkout (3 976 files indexed, `--release`):
|
||
|
||
| cursor | before | after |
|
||
|---|---:|---:|
|
||
| a port of `adc_ctrl_core` (action offered, 2 files edited) | 4.56 s | **7.1 ms** |
|
||
| a `prim_fifo_sync` instantiation (36-file fan-out) | 2.93 s | **83 ms** |
|
||
|
||
Both were checked to give the *same* answer as the whole-workspace
|
||
computation, which is the point: this is a smaller input to the same engine,
|
||
not a cheaper approximation. The second row is the ceiling — a module
|
||
instantiated all over OpenTitan really does need its 36 files, and the engine
|
||
parses them twice (plan, then verify); 1.3 ms of that 83 ms is reading them.
|
||
|
||
Reproducible without that checkout:
|
||
`perf::a_code_action_at_an_instantiation_before_and_after` generates 500 files
|
||
of 200 lines plus a module instantiated in three of them, and runs both shapes
|
||
over the same workspace in the same run:
|
||
|
||
| | |
|
||
|---|---:|
|
||
| whole workspace (what the handler did until this round) | 725 ms |
|
||
| the module's fan-out | **0.41 ms** |
|
||
| `sources()` alone — the read, without the engine | 14.5 ms |
|
||
| `prepare_rename`, deliberately untouched this round | 249 ms |
|
||
|
||
The last row is the follow-up this round did not take: a rename must see every
|
||
file that could name the symbol, so its subset is a different argument. It is
|
||
sent when the user presses the rename key, not per cursor move.
|
||
|
||
## Before / after — round 7, Lane B (2026-08-28)
|
||
|
||
`performance.md` §6d: `textDocument/completion` cost **34–66 ms and fired on
|
||
every keystroke**, worst at 0–4 typed characters — the beginning of every
|
||
identifier. Typing `aes_reg_top` one character at a time cost **201 ms** of
|
||
blocked single-threaded loop. The report guessed the cost was "scanning the
|
||
3 976-file symbol table"; the probe says otherwise.
|
||
|
||
**Where it actually was.** `perf::completing_one_keystroke_at_a_time` runs the
|
||
same request at the same prefixes with the cursor at module-item position
|
||
(every tier runs) and inside an expression (tier 0 is gated off). Over a
|
||
generated corpus of 4 000 files:
|
||
|
||
| prefix | at an item, before | in an expression (no tier 0) |
|
||
|---|---:|---:|
|
||
| `` (empty) | 53.2 ms | 0.19 ms |
|
||
| `aes_` | 49.7 ms | 0.19 ms |
|
||
|
||
Everything that is not tier 0 — the index tier, the word tier, the scope
|
||
gates, building and serialising 512 items — is **0.19 ms**. The whole cost was
|
||
**tier 0, the module skeletons**: up to 64 per keystroke, each one a read of
|
||
the declaring file and a `parse_source_tolerant` over **all** of it, to read a
|
||
header a few hundred bytes long. One skeleton off a 1 214-line file: 2.71 ms
|
||
of parse for 16 µs of planning.
|
||
|
||
Two changes, both of which must leave the items byte-identical (pinned by
|
||
`completion::tests::the_header_slice_plans_exactly_what_the_whole_file_plans`
|
||
and `candidates::tests::the_module_table_answers_exactly_what_module_names_answers`):
|
||
|
||
1. **Parse the header, not the file.** `completion::module_header` slices the
|
||
declaring file at the `;` that ends the module header — anchored on the
|
||
index's own `name_span`, found by lexing a bounded window, and refused
|
||
outright for any header shape it does not recognise. The prefix is kept
|
||
byte for byte so every span the plan reads still points where it did.
|
||
2. **Table the module names.** Tier 0 asked `vlog_refactor::module_names`,
|
||
which calls `WorkspaceIndex::workspace_symbols("")` — building and sorting
|
||
a record per declaration in the workspace, **per keystroke**.
|
||
`Candidates::modules` is that list, built once beside the index.
|
||
|
||
| generated corpus, 4 000 files of 1 200 lines | before | after |
|
||
|---|---:|---:|
|
||
| completion at the empty prefix | 53.2 ms | **3.17 ms** |
|
||
| at `a` | 52.4 ms | **3.14 ms** |
|
||
| at `aes_` | 49.7 ms | **3.26 ms** |
|
||
| at `aes_0001` (1 item) | 0.31 ms | **0.017 ms** |
|
||
| one skeleton: `instantiation_plan` over the whole file | 2.71 ms | — |
|
||
| one skeleton: over its header alone | — | **16.5 µs** (slicing it: 7.1 µs) |
|
||
|
||
Over the real checkout, driven through the shipped binary with
|
||
`performance.md`'s own client (3 976 files, workspace scope, warm):
|
||
|
||
| request | before (`performance.md` §6d) | after |
|
||
|---|---:|---:|
|
||
| completion, empty prefix | 63–66 ms | **13.1–15.0 ms** |
|
||
| completion, `a` | 58–61 ms | **13.2–13.5 ms** |
|
||
| completion, `aes_` | 35 ms | **15.0–15.7 ms** |
|
||
| completion, `prim_` | 16–19 ms | **5.8–6.9 ms** |
|
||
| completion, `clk` | 5.7–6.0 ms | **2.4–2.8 ms** |
|
||
| completion, `aes_reg` | 5.0 ms | **0.32–0.69 ms** |
|
||
| completion, `zzzz` | 1.4–2.0 ms | **0.06–0.31 ms** |
|
||
| typing `aes_reg_top`, 11 keystrokes | **200.9 ms** | **64.5 ms** |
|
||
|
||
**The generated corpus is 3.2 ms and the real one is 13 ms, and the difference
|
||
is real rather than noise.** `perf::completing_over_a_real_project` — the same
|
||
measurement pointed at whatever `LUCISV_PERF_CORPUS` names, skipped when it is
|
||
unset — breaks tier 0's remaining bill down over opentitan's own modules:
|
||
|
||
| prefix | modules planned | read each | slice each | plan each |
|
||
|---|---:|---:|---:|---:|
|
||
| `` (empty) | 64 | 16.8 µs | 62.2 µs | 68.2 µs |
|
||
| `aes_` | 59 | 15.0 µs | 63.8 µs | 101.6 µs |
|
||
| `prim_` | 64 | 12.3 µs | 23.5 µs | 19.2 µs |
|
||
| `clk` | 34 | 2.1 µs | 0.7 µs | 1.1 µs |
|
||
|
||
opentitan's headers are simply bigger: `aes_control_fsm_n`'s is 6.6 KB of
|
||
commented ports. That measurement is also what set `HEADER_WINDOWS`: at the
|
||
first ladder tried (top rung 4 KB) four of the 64 `aes*` modules overflowed it
|
||
and paid a whole-file parse of a 24–52 KB file — 10 ms of the 12. Raising the
|
||
top rung to 16 KB removed every fallback and cost the common case nothing,
|
||
because the common header still ends inside the first 256-byte rung (59% of
|
||
opentitan's 344 RTL modules do).
|
||
|
||
**What is left, and why it was not taken.** ~10 ms of a worst-case opentitan
|
||
completion is 64 real header parses, and the items are required to be
|
||
identical, so the only ways down are a cache or a protocol change:
|
||
|
||
- memoize the plan per (module, index generation) — correct only if the cache
|
||
is dropped on every unsaved edit to a declaring buffer, which
|
||
`Candidates` currently is not (it is rebuilt at `didSave`), so it would need
|
||
a new invalidation rule rather than an existing one;
|
||
- `completionItem/resolve`: send tier 0's items with labels only and compute
|
||
the skeleton on the lightbulb — ~0 ms per keystroke, but it changes what the
|
||
first response contains and needs `resolveProvider` in the capabilities.
|
||
|
||
Both are the same shape as the deferred `codeAction/resolve` item in
|
||
`TODO.md` §10 and belong with it.
|
||
|
||
**`documentHighlight`, `performance.md` §7 — a functional bug, not a perf
|
||
one.** It answered 0 results at every position tried while `references`
|
||
answered 7 and 10 at the same positions. Root cause and fix are in
|
||
`docs/features/references-nav/README.md`; the number here is only that it is
|
||
still fast now that it answers: **0.05–0.15 ms** against the 0.03–0.12 ms it
|
||
took to answer nothing.
|
||
|
||
**The scope-depth default, `performance.md` §4.** The shipped
|
||
`lucisv.index.scopeDepth` moves 0 → 2.
|
||
`perf::what_the_scope_depth_default_costs` measures every rung over an
|
||
opentitan-shaped tree (12 blocks of 20 `rtl/` files plus a `dv/tb/` file, the
|
||
buffer opened three levels down):
|
||
|
||
| depth | files indexed | index names | scan |
|
||
|---:|---:|---:|---:|
|
||
| 0 | **1** | 5 | 0.6 ms |
|
||
| 1 | 1 | 5 | 0.3 ms |
|
||
| 2 | **21** | 25 | 15.0 ms |
|
||
| 3 | 252 | 256 | 185.0 ms |
|
||
|
||
Depth 0 reproduces the trap exactly: one file indexed, so every cross-file
|
||
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.
|
||
|
||
## Before / after — round 8 (2026-08-29)
|
||
|
||
`performance_take2.md` §5b: the first F12 from a testbench into its own RTL at
|
||
the shipped `scopeDepth: 2` raises the scope from one IP block to the whole of
|
||
`hw/ip`, and take 2 measured 1.4–1.7 s of frozen loop for it.
|
||
|
||
**The diagnosis in the brief did not survive the measurement, and that is the
|
||
first result.** The widen was *not* falling back to a whole rescan and was *not*
|
||
re-indexing the block it already held: with `hw/ip/aes` already in scope, the
|
||
jump's bar reads **1 685 files, not 1 807**, and every one of them is a file the
|
||
index did not hold. `widen_of` sees an add (the contained directory stays in the
|
||
list beside the containing one) and `begin_widen` diffs **by file against the
|
||
index**. Both are pinned by tests this round rather than left to be re-derived.
|
||
|
||
**What the second was actually paying for**, `hw/ip` at the default scope, warm
|
||
store, stage by stage:
|
||
|
||
| stage of the 1 807-file widen | before | after |
|
||
|---|---:|---:|
|
||
| walk the added folder and read the new files | 100 ms | 100 ms |
|
||
| the scan loop (hash, decode the records, **lex for words**) | 405 ms (325 of it the lex) | 405 ms |
|
||
| `index.absorb` | 31 ms | 31 ms |
|
||
| **`candidates.absorb`** | **403 ms** | **43 ms** |
|
||
| `includes.absorb` | 20 ms | 20 ms |
|
||
|
||
The word table is a sorted `Vec`, and the widen inserted each new word into it
|
||
on its own — one memmove of the table's tail per word, quadratic in the batch.
|
||
Counted per batch and merged in one pass, it is 9× cheaper and the answer is
|
||
the same table `Candidates::build` sorts from the same counts.
|
||
|
||
End to end, `/Users/guoliangchen/repo/opentitan`, `--release` over stdio, the
|
||
`HEAD` binary and this one alternated in one session, timing the request sent
|
||
straight after each `didOpen`:
|
||
|
||
| `didOpen` at `scopeDepth: 2` | before | after |
|
||
|---|---:|---:|
|
||
| `hw/ip/aes/dv/tb/tb.sv` (widens to `hw/ip/aes`, 124 files) | 51 / 60 ms | 52 / 55 ms |
|
||
| `hw/ip/aes/rtl/aes.sv` (raises to `hw/ip`, **1 685 new**) | 935 / 881 ms | **555 / 564 ms** |
|
||
| the same jump on a **cold** store (1 683 parses) | 1 529 ms | **1 175 ms** |
|
||
| `kmac`, `hmac`, `spi_device` after it (already in scope) | 3–6 ms | 3–6 ms |
|
||
|
||
The cold row is take 2's own 1.4–1.7 s reproduced. **What is left is real
|
||
work**: 1 683 files this index has never seen, of which 325 ms is re-lexing
|
||
them for the completion word table — the persistent store holds a file's facts
|
||
but not its words, and putting them there is a `FACTS_FORMAT` change, filed in
|
||
`TODO.md` §10. The widen still does not interleave, so this is one bar the user
|
||
watches, once per session per big widen.
|
||
|
||
Reproducible without that checkout:
|
||
`perf::what_a_widen_that_subsumes_the_old_scope_costs` generates 20 blocks ×
|
||
(25 rtl + 10 dv) files whose every name is its own file's, opens a testbench and
|
||
then its RTL sibling at depth 2, and asserts the widened index fingerprints
|
||
identically to the whole rescan's:
|
||
|
||
```text
|
||
scope 35 -> 700 files; the widen read 667 of them (the 35 already indexed are not re-read)
|
||
whole rescan 664 ms, subsuming widen 653 ms (landing it: 62.9 ms before, 51.8 ms after)
|
||
```
|
||
|
||
The two columns being close is honest and is the point of the shape: when the
|
||
subsuming folder is twenty times the old scope, skipping the overlap saves 5 %.
|
||
What the round bought is in the landing figure, and it grows with the workspace's
|
||
vocabulary — which is why the opentitan table above is the one that matters.
|
||
|
||
## What it would take to go faster
|
||
|
||
Ranked by what the measurements above say is there, with what each would
|
||
cost. None of these were attempted; each is a future round.
|
||
|
||
0. **Answer requests during the startup scan — 780 ms cold, 287 ms warm, on
|
||
the first request of a session.** New in round 3's measurements (D2 above)
|
||
and the largest single number on this page. It is not a code-speed problem:
|
||
the work is already as fast as the persistent cache can make it, and what
|
||
costs the user is that the message loop has not started yet. Any fix is a
|
||
change to what an answer *means* while the index is half-built, so it needs
|
||
a design round, not an optimisation.
|
||
→ **Done in round 4**, 780 → 15.5 ms cold and 287 → 12.8 ms warm; the
|
||
design round it needed is `docs/features/scan-interleave/README.md`, and
|
||
what an answer means mid-scan is written down there. What is left of this
|
||
item is 6.9 ms of eager file reading before the scan's first file.
|
||
1. **Incremental lexing and parsing — 24.5 ms of a 31 ms flush at 10 000
|
||
lines (79 %).** This is the only large lever left. It is also the one
|
||
change that runs straight into `CLAUDE.md`'s hard invariants 1 and 2: the
|
||
parser is what the "never corrupt code" and idempotency guarantees rest
|
||
on, and an incremental parser that is right on 99 % of edits is worse than
|
||
none. The change debounce already removed most of the *repetition* per
|
||
keystroke, which is why this was not attempted here. The number that would
|
||
justify it: **37.6 ms**, the felt latency of one keystroke in a
|
||
10 000-line buffer, of which roughly 30 ms is lex + parse.
|
||
2. **A cheaply-clonable `Token` — 2.40 ms, 7.7 % of a flush.**
|
||
`Document.tokens` must be a separate copy because `parse_tolerant` takes
|
||
ownership and steals `leading`/`trailing` out of the tokens it parses; the
|
||
copy is 94 961 `String` allocations. Interning the text, or an `Rc<str>`,
|
||
would remove most of it — but `Token` is `vlog_parser`'s public type and
|
||
the formatter reads it everywhere, so this is a cross-crate change for
|
||
under 8 %.
|
||
3. **One tree walk for the whole lint pass — 1.40 ms, about 4 % on top of a
|
||
flush.** `vlog_linter::lint` is `for rule in enabled { rule.check(ctx) }`,
|
||
one walk per rule, and the same engine serves `lucisv check`. Fusing them
|
||
is a `vlog_linter` refactor, and the editor and CI must not disagree about
|
||
what a violation is.
|
||
4. **`completion.rs`'s comment gate**, the last whole-buffer walk on a
|
||
per-keystroke request path. Not measured on its own; it is one pass over
|
||
the token vector plus its trivia, so the sweep figures above (77.5 µs at
|
||
10 000 lines) are the right order of magnitude for it. Doing it properly
|
||
means giving the lexer a way to answer "which comment covers this byte",
|
||
which is a `vlog_parser` question and not a `completion.rs` one.
|
||
5. **`CHANGE_DEBOUNCE` itself** is not a code problem: 150 ms of a lone
|
||
keystroke's 164 ms round trip is the timer. It only bites clients that ask
|
||
for nothing after a change, and it was set deliberately. Now that it is
|
||
measured, a future round has the number to argue about.
|
||
|
||
## Status / TODO
|
||
|
||
- [x] `crates/lucisv_server/src/perf.rs` — eight `#[ignore]`d measurements,
|
||
std only, each with the command to run it.
|
||
- [x] `analyze`, `Document::new`, hover (local + closed cross-file),
|
||
`WorkspaceIndex::update_file`, at 1k and 10k lines.
|
||
- [x] Before/after where it was cheap: A2 (two ways), A3 and C1.
|
||
- [x] Machine, command and date recorded above.
|
||
- [x] **Round 1's first open TODO, resolved (round 2, 2026-08-28):**
|
||
end-to-end request latency over the wire, measured against the shipped
|
||
binary — a single `didChange`, a burst of ten (with the publish count
|
||
that turns A1's arithmetic into a measurement), and the
|
||
change-then-request shape a real editor produces.
|
||
`tests/e2e.rs::a_keystroke_round_trip_over_the_wire`.
|
||
- [x] **Added in round 2:** one flush stage by stage, including the
|
||
`diagnostics::all` pass that runs on every publish and that round 1's
|
||
table did not account for.
|
||
- [x] **Added in round 3 (2026-08-28):** a hover into a big closed file with
|
||
the **first touch and the repeat reported separately**
|
||
(`perf::hovering_into_a_big_closed_file_first_touch_and_repeat`) — every
|
||
earlier hover probe reported a mean, which hides exactly the split the
|
||
owner's report was about — and the first request of a session against
|
||
the shipped binary, with a cold store and a warm one
|
||
(`tests/e2e.rs::a_hover_issued_during_the_initial_scan_waits_for_it`).
|
||
`perf::breaking_down_one_flushed_keystroke`.
|
||
- [x] **Added in round 4 (2026-08-28):** what one mid-scan publish costs
|
||
against the per-file parse it is interleaved with
|
||
(`perf::publishing_a_half_built_index_mid_scan`, at 50 / 200 / 800
|
||
files), and what a scan does *before* its first file — the block no
|
||
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
|
||
report has not moved, and round 1's name index is still four bytes per
|
||
symbol. Worth doing before anything interns tokens, which is item 2 of
|
||
*What it would take to go faster* and is a memory trade as much as a
|
||
time one.
|
||
- [x] **Round 1's last "not measured", closed for completion (round 7,
|
||
2026-08-28):** `perf::completing_one_keystroke_at_a_time` measures the
|
||
whole request at nine prefixes, in both positions that gate tier 0, over
|
||
a 4 000-file corpus — which is how the cost was found to be tier 0 and
|
||
not the symbol table `performance.md` suspected.
|
||
`perf::completing_over_a_real_project` does the same over a corpus named
|
||
by `LUCISV_PERF_CORPUS`, and skips when it is unset.
|
||
- [x] **Added in round 7 (2026-08-28):** what the shipped
|
||
`lucisv.index.scopeDepth` costs and buys, rung by rung, on an
|
||
opentitan-shaped tree (`perf::what_the_scope_depth_default_costs`).
|
||
- [x] **Added in round 8 (2026-08-29):** what a widen that *subsumes* the
|
||
folder already in scope costs, at the shipped depth, with the files it
|
||
actually reads reported beside the scope's size and the landing of the
|
||
scan timed on its own — the stage the round's fix is in
|
||
(`perf::what_a_widen_that_subsumes_the_old_scope_costs`).
|
||
- [ ] Not measured: signature help and semantic tokens end to end. Each has a
|
||
whole-buffer pass somewhere; only their token lookups have ever been
|
||
measured. Completion was the third of that list and is now done — and it
|
||
was 34–66 ms, which is the reason to finish the other two.
|
||
|
||
## Work log
|
||
|
||
**2026-08-28 — dev.** Wrote `perf.rs` and took the numbers above (part A4 of
|
||
the LSP performance round). Chose one module of six tests over a test per
|
||
crate so that a single command produces the whole table. The generated-module
|
||
generator lives beside the tests rather than in a shared helper — it has one
|
||
user.
|
||
|
||
Renamed `hover.rs`'s QA measurement
|
||
`hovering_into_a_large_closed_file_reads_it_twice` →
|
||
`..._reads_it_once`, since the doubled read it was named for is what A2
|
||
removed. The QA log in `docs/features/hover-declarations/README.md` still
|
||
names the old spelling; that section belongs to QA and was left alone.
|
||
|
||
**2026-08-28 — dev (QA fixes).** No number above moved, and none was
|
||
re-measured, because nothing on a measured path changed shape:
|
||
|
||
- The hover fixes (PDS-1, PDS-2, PDS-4) are all inside `attached_lines`,
|
||
which part **B** already records as unmeasured. The added work is a
|
||
`strip_suffix` per composed line and a below-comment walk that now also
|
||
runs when a comment sits above — a handful of `line_range` lookups against
|
||
the 142 µs *file read* that dominates the "hover closed" figure.
|
||
- CD-1 only *removes* work (a closing buffer's `Document::new` and publish),
|
||
and the debounce's own A1 numbers are arithmetic over `Document::new`,
|
||
which is untouched.
|
||
- PDS-3 widens one `bind_port_decl` branch from ports to task/function
|
||
arguments: one hash lookup per declarator of a body port declaration
|
||
inside a task or function. `perf.rs`'s generated modules contain no
|
||
tasks, so the `analyze` / `Document::new` / `update_file` figures cannot
|
||
have moved at all.
|
||
|
||
**2026-08-28 — dev (round 2).** Added
|
||
`perf::breaking_down_one_flushed_keystroke`,
|
||
`perf::finding_one_token_against_sweeping_the_stream` and
|
||
`tests/e2e.rs::a_keystroke_round_trip_over_the_wire`, and **re-measured every
|
||
figure in this document** on the same machine from the commands written
|
||
beside them — the tables above are one run of each, not a mix of runs across
|
||
days. The old figures are gone rather than kept alongside; every pair was
|
||
within the noise this document already budgets for, and carrying two columns
|
||
of the same measurement would invite reading a difference into scheduling.
|
||
Round 1's figures are not lost — the QA log below quotes all of them in its
|
||
own table, dated, and that section belongs to QA and was left alone.
|
||
|
||
The round's changes are in `docs/features/interactive-latency/README.md`.
|
||
Only C1 touched shipped code, and it touched no stage of a flush, so the
|
||
flush table is a baseline for the next round rather than an after.
|
||
|
||
Two things are recorded here that a future round should not have to
|
||
rediscover. First, the e2e measurement reuses `e2e.rs`'s existing `Live`
|
||
session helper; the only shared code that changed is that `Live::finish` now
|
||
returns the publish count it saw on the way out, which is what makes the
|
||
debounce's coalescing countable. Second, `perf::generated_module` now has a
|
||
copy in `tests/e2e.rs` — a binary crate's modules are not reachable from an
|
||
integration test — and the two must stay the same shape or the in-crate table
|
||
and the over-the-wire table stop being readable against one another.
|
||
|
||
**2026-08-28 — dev (round 7, Lane B).** Added three measurements and one
|
||
before/after section, all under *Before / after — round 7*:
|
||
|
||
- `perf::completing_one_keystroke_at_a_time` — the completion request at nine
|
||
prefixes, in both positions that gate tier 0, over a generated 4 000-file
|
||
corpus. The two columns are the whole finding: everything that is not the
|
||
module-skeleton tier is 0.19 ms, at every prefix, before and after.
|
||
- `perf::completing_over_a_real_project` — the same, over `LUCISV_PERF_CORPUS`,
|
||
with tier 0's per-module bill split into read / slice / plan. **Skipped when
|
||
the variable is unset**, so this crate still depends on no checkout it does
|
||
not ship. It is what caught the four `aes_control*` modules whose 6.6 KB
|
||
headers overflowed the first window ladder and paid a whole-file parse; the
|
||
shipped `HEADER_WINDOWS` top rung of 16 KB comes from that measurement and
|
||
from a survey of opentitan's 344 RTL headers, not from a guess.
|
||
- `perf::what_the_scope_depth_default_costs` — every rung of the scope ladder
|
||
over an opentitan-shaped tree, which is the number behind the
|
||
`lucisv.index.scopeDepth` default moving 0 → 2.
|
||
|
||
`completion_corpus`'s files are 1 200 lines rather than the 300 first tried:
|
||
at 300 the generated corpus reproduced `performance.md`'s 34–66 ms almost
|
||
exactly, and going bigger showed the *shape* of the cost (a whole-file parse
|
||
per skeleton) far more clearly — 2.71 ms of parse for 16 µs of planning.
|
||
|
||
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.
|
||
|
||
- **Machine match confirmed.** `sysctl -n machdep.cpu.brand_string` →
|
||
`Apple M1 Max`; `sw_vers` → macOS 27.0, build `26A5421a` — exactly the
|
||
machine named in the README's own table, on the same checkout.
|
||
- **Re-ran the exact reproduce command**, `cargo test --release -p
|
||
lucisv_server perf:: -- --ignored --nocapture --test-threads=1`, and
|
||
compared every figure against the table:
|
||
|
||
| what | table | re-measured |
|
||
|---|---|---|
|
||
| `analyze`, 1k / 10k | 274 µs / 3.79 ms | 287.6 µs / 3.806 ms |
|
||
| `Document::new`, 1k / 10k | 2.60 ms / 31.1 ms | 2.600 ms / 31.72 ms |
|
||
| hover local, 1k / 10k | 1.79 µs / 0.97 µs | 3.35 µs / 1.01 µs |
|
||
| hover closed, 1k / 10k | 35.2 µs / 160 µs | 34.4 µs / 172 µs |
|
||
| — one read of it, 1k / 10k | 26.9 µs / 142 µs | 26.7 µs / 147.6 µs |
|
||
| `update_file`, 1k / 10k | 2.73 ms / 31.4 ms | 2.695 ms / 32.45 ms |
|
||
| — the clone, 1k / 10k | 60 µs / 528 µs | 60.7 µs / 516.7 µs |
|
||
| linear scan, 1k / 10k | 763 ns / 8.41 µs | 793 ns / 8.21 µs |
|
||
| name-sorted, 1k / 10k | 106 ns / 133 ns | 93 ns / 134 ns |
|
||
|
||
Every pair is within the noise the README itself budgets for — including
|
||
the hover-local 1k figure, which the README already calls out by name as
|
||
"that measurement's noise floor, not a result" (mine is higher still,
|
||
3.35 µs vs. 1.79 µs, and still a handful of pointer chases either way).
|
||
Nothing here is scaled, remembered, or overclaimed.
|
||
- **Re-ran the older, separately-commanded measurement** too: `cargo test
|
||
--release -p lucisv_server large_closed -- --ignored --nocapture
|
||
--test-threads=1` → **17.0 ms** against the documented "34 ms → 16.3 ms."
|
||
Matches the README's own honesty caveat exactly ("read it as 'about half',
|
||
not as 2.08×" — different runs, different days).
|
||
- **`perf.rs` measures what its name says** — spot-checked
|
||
`hovering_across_files_into_a_closed_file` and
|
||
`looking_up_one_name_against_scanning_every_symbol` against `hover.rs`'s
|
||
and `lib.rs`'s actual entry points (`hover::hover`, `Semantics::
|
||
symbols_named` vs. a hand-rolled linear scan over `symbols()`) — both call
|
||
the real, shipped functions, not a stand-in.
|
||
- **A1's "before/after" is correctly labeled "not measured directly"** — it
|
||
is arithmetic over the already-verified `Document::new` figures, and the
|
||
README says so; no separate claim to check.
|
||
- **B's "not measured, none is claimed"** — confirmed true: no perf test
|
||
exercises `fenced_sections`/`attached_lines`, and the README does not say
|
||
one does.
|
||
|
||
**2026-08-28 — QA (round 2).** Findings and the full gate output are recorded
|
||
in `docs/features/interactive-latency/README.md`'s QA log, which is this
|
||
round's owning feature; summarized here since this document is where the
|
||
numbers live.
|
||
|
||
- Every figure in *Over the wire* and *One flush, stage by stage* reproduced
|
||
within the noise this document budgets for, from a fresh
|
||
`cargo test --release -p lucisv_server perf:: -- --ignored --nocapture --test-threads=1`
|
||
and `cargo test --release -p lucisv_server --test e2e a_keystroke -- --ignored --nocapture --test-threads=1`
|
||
on this session's run of this machine.
|
||
- **C1's identity claim** (six sweeps → binary searches, none changed an
|
||
answer) held under a hand-traced check of all six call sites, including
|
||
the empty-token and large-file-fast-path edges, and under an independent
|
||
check of the `state.rs` monotonicity precondition against `vlog_parser`'s
|
||
own much wider corpus/fuzz tests (`tests/spans.rs`, `tests/error_recovery.rs`)
|
||
— no gap found.
|
||
- **One methodology finding, IL-1 (medium)**, on the e2e round trip's burst
|
||
measurement: the "1 publish(es)" figure for a burst of ten is not the
|
||
order-independent count its own doc comment claims — a stray extra publish
|
||
in the window between the burst and `Live::finish`'s drain could be
|
||
silently absorbed by an unrelated `wait_for` later in the same test and
|
||
never counted. Full detail and repro in
|
||
`docs/features/interactive-latency/README.md`. Not a claim about a real
|
||
double-publish (the debounce is understood to coalesce to one), and not
|
||
fixed — closing it is a test-restructuring decision for the dev.
|
||
- The two `generated_module` copies (this crate's `perf.rs` and `e2e.rs`'s)
|
||
differ by one trivia line, not the byte-identical shape their own comment
|
||
implies; verified harmless (comments are not tokens, and the tables stay
|
||
readable against each other). Detail in the same QA log.
|
||
- **Verdict: SHIP WITH FIXES noted, none applied.**
|
||
|
||
## Review
|
||
|
||
**2026-08-28 — lead.** Accepted as the round's record.
|
||
|
||
The discipline here is what makes the numbers usable later: one command, one
|
||
machine block, means rather than single runs, `--test-threads=1` justified by
|
||
a contaminated first attempt that reported a cross-file hover as cheaper than
|
||
the file read it performs. Refusing criterion was the right call against
|
||
`CLAUDE.md`'s dependency rule, and the `#[ignore]`d-measurement pattern was
|
||
already this repo's idiom rather than an invention for this round.
|
||
|
||
I re-ran every measurement independently and the figures reproduce. Two
|
||
claims were softened at review rather than left as written: the wire-latency
|
||
rows are re-measured after the IL-1 methodology fix (164/202 ms lone,
|
||
4.35/37.6 ms with a request following), and the lone-keystroke row now says
|
||
plainly that round 1 made that case *slower* — 150 ms of it is the debounce
|
||
timer, and a client that asks for nothing after a change waits it out. A perf
|
||
document that only records wins is not a perf document.
|
||
|
||
What I want the next round to inherit: the felt-latency number is **37.6 ms**
|
||
for one keystroke in a 10 000-line buffer, roughly 30 ms of it lex and parse.
|
||
That is the figure any incremental-parsing proposal has to be argued against,
|
||
and it now exists.
|
||
|