Docs debt: performance_take2.md, the merged-wave measurement, finally checked in beside take 1

Written 2026-08-29 as the owner-requested second opentitan round; referenced
by CHANGELOG 0.15.0, docs/perf/README.md and the index-scope README ever
since, but never staged. Placed in docs/ so its relative link to
performance.md resolves.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
lucioandClaude Fable 5 committed 2026-08-30 14:17:00 -07:00
1 parent a1fa402fd8
commit 1cfbab4a56
1 file changed
+677
+677
View File
@@ -0,0 +1,677 @@
# lucisv-server LSP performance against opentitan — take 2
Same corpus, same scenarios, same client, same machine as
[`performance.md`](performance.md); a different binary. Take 1 measured
`bf9170a`+ (the in-progress `codeAction` fan-out fix compiled in); take 2
measures **`ee1efe3` — the merged performance wave** (Lane A: `prepareRename`,
`rename`, `willRenameFiles`; Lane B: completion hot path, `documentHighlight`
fix, `scopeDepth` default; plus `ad27ed2` `codeAction` fan-out and `bf9170a`
incremental widen, already present in take 1).
Every number is a client-observed round trip on a monotonic clock
(`time.perf_counter`), which is what the editor — and therefore the user —
actually experiences. Every table carries take 1, take 2, and the factor.
---
## 0. Read this first: still no server-side instrumentation
The take-2 binary is the ordinary release build, not an instrumented one.
Verified: `strings -a` finds no `timing`, `answered in`, `handled in`, or
`elapsed` literal anywhere in it. So, exactly as in take 1, **there is no
server-side handling column below** — only client round trips.
The stand-in is the same **transport baseline**: an unknown request method
(`$/lucisvNoSuchMethod`) the server rejects without doing any work.
| | take 1 | take 2 |
|---|---:|---:|
| transport baseline, min | 0.02 ms | **0.019 ms** |
| transport baseline, median across sessions | ≈0.05 ms | **≈0.05 ms** |
| transport baseline, worst observed | 0.33 ms | 0.14 ms (one contended session: 10.6 ms) |
The floor is unchanged, so the two documents' numbers are directly comparable:
everything above ~0.5 ms is server work, and for an isolated request
`client round trip ≈ server handling + 0.05 ms`.
---
## 1. Environment and provenance
| | take 1 | take 2 |
|---|---|---|
| Machine | Apple M1 Max, 10 cores, 64 GB | **same machine** |
| OS | macOS 27.0 (26A5421a) | same |
| Date | 2026-08-28 ~21:50–22:15 | **2026-08-29 ~00:45–02:00** |
| Binary | 4 120 288 B, sha256 `ce7e15db…dfe7cc`, dirty tree at `bf9170a`+ | **4 155 456 B, sha256 `a45d814c…c988edd`**, Mach-O arm64, packaged build of master `ee1efe3` |
| Repo HEAD the binary was built from | `bf9170a` + uncommitted `code_actions` fix | **`ee1efe3`** — *"Merge performance-wave Lane A"* |
| Corpus | `/Users/guoliangchen/repo/opentitan` @ `0098135264` — 3979 files, 3976 indexed, 3 skipped | **identical, byte for byte** (`git status`: only the same pre-existing `tb.sv` trailing-space edit, mtime 20:39 on 2026-08-28, untouched by either session) |
| Scenario file | `hw/ip/aes/dv/tb/tb.sv` (100 lines); `aes` instantiated at 0-based line 44 col 2; `.clk_i` at line 49; `aes` declared at `hw/ip/aes/rtl/aes.sv:9` | identical, positions resolved from the file text at run time |
| Client | `scratchpad/perf/{lspclient,bench,bench2,bench3,typing}.py` | **the same scripts**, copied to `scratchpad/perf2/` with three changes (below) |
| Advertised capabilities | `caps.txt` | **identical set**; `implementationProvider` still absent and still not measured |
### The four client changes, and why
1. **`SERVER` points at the take-2 binary.** Nothing else in `lspclient.py`'s
wire handling changed.
2. **The configuration reply grew three more scope words** — `empty`
(reply `[{}]`), `default` (reply carries no `scope`/`scopeDepth` at all),
and `depth0` (`{"scope":"folder","scopeDepth":0}`) — because the shipped
default changed under us and all three now have to be measured.
3. **Cache warmth is controlled through `initializationOptions.storagePath`,
not only `index.cachePath`.** This is a methodology *fix*, and take 1's
numbers should be read with it in mind: `index.cachePath` arrives in the
pulled configuration, and `state.rs::set_client_settings` only reopens the
store *"at the next whole rescan"*. A reply that matches the defaults forces
no rescan, so the in-flight first scan keeps reading `~/Library/Caches` —
i.e. a "cold" run at the default scope was silently warm. My first take-2
attempt reproduced this exactly (a `rm -rf`'d cache directory that was never
created, and a scan reporting "123 from cache"). `storagePath` is read at
`initialize`, before any scan, so it controls warmth for every config.
Take 1's *workspace*-scope cold/warm split is unaffected — switching to
workspace scope does force a rescan, and its 22 MB store was written — but
take 1's folder-scope "cold" row was not really cold. It indexed one file,
so nothing hangs on it.
4. **A `LUCISV_EXTRA_INDEX` environment knob** merges extra keys into the
`index` object of the configuration reply. Used for exactly one experiment:
`{"logFiles": false}`, to rule logging out as the cause of the warm-scan
outliers (§4). Unset everywhere else.
**Cache state is stated per table.** "Cold" = the store directory was `rm -rf`'d
immediately before. "Warm" = it carries a previous session's store (22 MB for
the full workspace, 1.0 MB for the new default scope).
---
## 2. Summary table — worst first, take 1 vs take 2
Workspace scope, warm cache, unless the row says otherwise. "Repeats" is the
range over the 2nd–4th (or 2nd–6th) identical request in the same session.
**Factor** compares first tries.
| Action | T1 first | T1 repeats | T2 first | T2 repeats | Factor |
|---|---:|---:|---:|---:|---:|
| `textDocument/rename` on `aes` (edits computed, not applied) | 6 355 ms | 3 601 – 8 659 ms | **115 ms** | 107 – 121 ms | **55×** |
| — anything queued behind that rename | 5 079 ms | — | **108 ms** | — | **47×** |
| `textDocument/prepareRename` on `aes` (pressing F2) | 2 999 ms | 1 723 – 2 597 ms | **0.07 ms** | 0.05 – 0.09 ms | **≈43 000×** |
| — anything queued behind that prepareRename | 2 501 ms | — | **0.1 ms** | — | **≈25 000×** |
| `workspace/willRenameFiles` (renaming a file in the explorer) | *unmeasured* — re-measured now on the take-1 binary: **313 ms** (270–286 repeats) | | **19.4 ms** | 15.4 – 16.3 ms | **16×** |
| Workspace scan, **cold** cache (didOpen → 3976 files indexed) | 3 003 ms | — | **2 958 ms** | 2 919 – 2 955 ms | 1.02× |
| Workspace scan, **warm** cache | 1 551 ms | 1 548 – 1 580 ms | **1 476 ms** | 1 495 – 1 558 ms (contended: up to 3 073 ms — §4) | 1.05× |
| `textDocument/codeAction` **on the `aes` instantiation** | 60.0 ms | 46 – 49 ms | **39.2 ms** | 36.4 – 37.6 ms | **1.5×** |
| — definition pipelined behind that codeAction | 52.7 ms | 47.4 – 58.2 ms | **37.7 ms** | 37.2 ms | **1.4×** |
| `textDocument/completion` at 1 typed character (512 candidates) | 61 ms | 34 – 66 ms | **15.3 ms** | 14.2 – 19.4 ms | **4.0×** |
| `textDocument/completion` at 0 typed characters | 63 – 66 ms | — | **14.8 – 18.6 ms** | — | **≈4×** |
| Typing 11 characters (`aes_reg_top`), completion each keystroke | 200.9 ms total | 18.3 ms/keystroke | **70.6 ms total** | **6.4 ms/keystroke** | **2.8×** |
| definition immediately after a widening `didOpen` (`spi_device.sv`) | 87.7 ms cold | 88.3 ms warm | **83.4 ms cold** | **45.7 ms warm** | 1.05× / 1.9× |
| definition immediately after a widening `didOpen` (`aes.sv`) | 48.4 ms cold | 49.3 ms warm | **22.3 ms cold** | **22.0 ms warm** | **2.2×** |
| definition immediately after a widening `didOpen` (`kmac`, `hmac`) | 37.7 / 27.0 ms | 34.1 / 23.9 ms | **33.5 / 18.2 ms** | **18.1 / 12.2 ms** | 1.1–1.9× |
| `workspace/symbol "aes"` (256 results) | 6.7 ms | 5.9 – 6.5 ms | 6.6 ms | 6.6 – 7.4 ms | **1.0×** (flat) |
| `textDocument/completion` at ≥5 typed characters (`aes_reg`, 20 items) | 5.3 ms | 4.0 – 5.0 ms | **0.59 ms** | 0.36 – 0.63 ms | **9×** |
| `initialize` → response | 2.0 – 8.0 ms | — | 2.1 – 8.9 ms | — | 1.0× |
| `textDocument/hover` on `aes` | 1.35 ms | 0.07 – 0.16 ms | 0.13 ms | 0.08 – 0.13 ms | 10× (first try) |
| `textDocument/codeAction` on a **comment line** (contrast) | 0.93 ms | 0.50 – 0.91 ms | 0.70 ms | 0.47 – 0.49 ms | 1.3× |
| `didChange` flush (measured with a `foldingRange` barrier) | 0.75 ms | 0.25 – 0.32 ms | 0.48 ms | 0.33 – 0.45 ms | 1.6× |
| burst of 10 `didChange` + one completion | 2.88 ms | — | **0.74 ms** | — | 3.9× |
| `textDocument/references` on `aes` (7 hits) | 0.61 ms | 0.39 – 0.72 ms | 0.66 ms | 0.38 – 0.43 ms | 0.9× |
| `textDocument/signatureHelp` inside the port list | 0.61 ms | 0.48 – 0.53 ms | 0.57 ms | 0.44 – 0.58 ms | 1.1× |
| `textDocument/definition` on `aes` | 0.49 ms | 0.11 – 0.18 ms | 0.27 ms | 0.05 – 0.11 ms | 1.8× |
| `textDocument/references` on `.clk_i` (10 hits) | 0.48 ms | 0.36 – 0.44 ms | 0.62 ms | 0.48 – 0.55 ms | **0.8× (slower)** |
| `textDocument/inlayHint` (whole 100-line file) | 0.36 ms | 0.21 – 0.25 ms | 0.38 ms | 0.23 – 0.34 ms | 0.9× |
| `textDocument/documentSymbol` | 0.13 ms | 0.13 – 0.21 ms | 0.16 ms | 0.11 – 0.48 ms | 0.8× |
| `textDocument/semanticTokens/full` | 0.16 ms | 0.12 – 0.13 ms | 0.16 ms | 0.14 – 0.16 ms | 1.0× |
| `textDocument/typeDefinition` on `aes` | 0.15 ms | 0.09 – 0.10 ms | 0.07 ms | 0.05 – 0.06 ms | 2.1× |
| `textDocument/diagnostic` (pull) | 0.13 ms | 0.04 – 0.07 ms | 0.11 ms | 0.06 ms | 1.2× |
| `textDocument/selectionRange` at the instantiation | 0.12 ms | 0.08 – 0.09 ms | 0.08 ms | 0.04 – 0.05 ms | 1.5× |
| `textDocument/documentHighlight` | 0.09 ms **(0 results — bug)** | 0.03 – 0.12 ms | 0.04 ms **(1 result — fixed)** | 0.04 – 0.07 ms | *correctness, not speed* |
| `textDocument/codeLens` | 0.10 ms | 0.03 – 0.07 ms | 0.05 ms | 0.04 – 0.06 ms | 2.0× |
| `textDocument/documentLink` | 0.09 ms | 0.05 – 0.08 ms | 0.09 ms | 0.05 – 0.07 ms | 1.0× |
| `textDocument/foldingRange` | 0.03 ms | 0.05 – 0.07 ms | 0.05 ms | 0.04 – 0.08 ms | 0.6× (noise) |
| `textDocument/definition` / `hover` on `.clk_i` | 0.05 ms | 0.03 – 0.07 ms | 0.04 – 0.06 ms | 0.03 – 0.06 ms | 1.0× |
| *transport baseline (does no work)* | *0.02 – 0.33 ms* | — | *0.019 – 0.14 ms* | — | *floor* |
**Two rows that are new in take 2 and belong near the top:**
| Action | take 1 | take 2 | Note |
|---|---:|---:|---|
| First `didOpen` of an RTL file **at the new default scope** (`hw/ip/aes/rtl/aes.sv`) | — (default indexed 1 file, nothing to widen into) | **1 411 – 1 731 ms** | **new regression**; see §5b |
| `codeAction` on a **high-fan-out** module (`prim_flop_2sync`, 128 instantiating files) | — | **201 ms first, 185 ms repeats** | residual, ~2.4× worse than the wave's own "83 ms at a 36-file fan-out" estimate; see §6a |
Everything below the `workspace/symbol` line was already inside the frame
budget in take 1 and stays there; the sub-millisecond rows move by ±0.1 ms,
which is at or under this harness's noise, and no conclusion should be drawn
from any of them individually.
---
## 3. The queue-blocking analysis — the pain is gone from two of the four rows
The server still runs a **single-threaded request loop**: one message off stdin,
answered to completion, then the next. So the latency a user feels for request
*R* is still *R*'s cost plus everything already queued. That structure is
unchanged; what changed is how big the leaders' bills are.
Each slow request was sent, then — back to back, no wait — the three requests a
real editor fires on every cursor move. All four timed from the same `t0`:
| Sent first (the blocker) | Its own cost, T1 | Its own cost, T2 | `definition` behind it, T1 | `definition` behind it, T2 | Factor |
|---|---:|---:|---:|---:|---:|
| `codeAction` on the `aes` token | 60.0 ms | **37.4 ms** | 60.0 ms | **37.4 ms** | 1.6× |
| `prepareRename` on `aes` | 2 500.7 ms | **0.1 ms** | 2 500.7 ms | **0.1 ms** | **≈25 000×** |
| `rename` on `aes` | 5 079.1 ms | **107.7 ms** | 5 079.1 ms | **107.7 ms** | **47×** |
| `workspace/symbol "aes"` | 9.7 ms | 6.9 ms | 9.7 ms | 7.0 ms | 1.4× |
`hover` and `documentSymbol` behind each leader land 0.02–0.4 ms after the
definition, as in take 1 — the queue is still strictly serial and the follower
still pays the leader's bill almost exactly.
Re-reading take 1's amplification numbers against take 2:
- **definition behind `prepareRename`: 2 500.7 ms → 0.1 ms.** The amplification
ratio is now ~1× because the leader costs nothing. This was take 1's
second-worst result and its most-argued-for fix; it is gone.
- **definition behind `rename`: 5 079.1 ms → 107.7 ms.** Still a ~1 000×
amplification over a lone definition, but 108 ms is a visible hitch rather
than a five-second freeze, and `rename` really is user-initiated.
- **definition behind `codeAction`: 60.0 ms → 37.4 ms.** This is the row take 1
called out by name, and it is the one that moved least. 37 ms is still more
than two frames, on a request that fires on **every cursor move**, and §6a
shows it gets much worse on modules with a bigger fan-out than `aes`'s six.
Take 1's two structural conclusions both survive:
1. **The absolute number matters more than the ratio.** Under ~16 ms is free,
16–100 ms is noticeable on a cursor move, over ~200 ms reads as a hang.
2. **`codeAction` and `completion` are the only slow requests on the hot path.**
After the wave this is *more* true, not less: the rename family left the
list entirely, so `codeAction` (37 ms typical, 185 ms at a large fan-out)
and `completion` (15 ms at a short prefix) are the whole of it.
### New in take 2: the scan interleaves, and it is visible
Take 1 always drained the progress bar before measuring, so it never recorded
what a request sent *during* the startup scan costs. Take 2 did (warm cache,
requests fired the instant after `didOpen`, before any progress was read):
| Scope | Requests sent mid-scan | Answer | Scan still ran until |
|---|---:|---|---:|
| workspace | definition 143.9 ms, hover 143.9 ms, documentSymbol 144.0 ms | **correct (1 result each)** | 1 544 ms |
| new default | definition 51.3 ms, hover 51.3 ms, documentSymbol 51.5 ms | correct | already over (51–59 ms, §4) |
So `172a034`'s interleaved scan holds on the real corpus: the first F12 of a
workspace-scope session answers correctly in ~144 ms against the index-so-far,
rather than waiting out the remaining 1.4 s.
**The contrast matters for §5b.** Only the *startup* scan interleaves;
`172a034` explicitly holds requests queued behind any rescan. A widen is a
rescan, so the 1 411–1 731 ms widen in §5b is paid in full by whatever the
editor sends next — it is a genuine freeze, not a 1.5 s bar with a responsive
server behind it.
---
## 4. Startup and scan, per scope config and cache state
Methodology unchanged: `didOpen tb.sv` → the last `$/progress` `end`, followed
by 1.5 s of silence. (The multi-bar trap take 1 documented is still real — the
server raises a 0-file bar, then the scope's bar, then any rescan's bar.)
**The default scope config changed in the wave**, so three configs are measured:
the new shipped default (`scopeDepth: 2`), an explicit `scopeDepth: 0` (take 1's
old default, for apples-to-apples), and workspace.
| Scope config | Cache | T1 didOpen → settled | T2 didOpen → settled | T1 files | T2 files |
|---|---|---:|---:|---|---|
| **new default** (`[{}]` — no opinion at all) | cold | *n/a* | **94.0 ms** | *n/a* | **124** |
| **new default** (`{"index":{}}`) | cold | *n/a* | 94.6 – 100.0 ms | *n/a* | 124 |
| **new default** | warm | *n/a* | **51.2 – 58.6 ms** | *n/a* | 124, 123 from cache |
| explicit `scopeDepth: 0` (T1's default) | cold | 102.2 ms | **98.9 ms** | 1 | 1 (after a 92.5 ms 124-file scan is thrown away) |
| explicit `scopeDepth: 0` | warm | 101.1 ms | **55.0 ms** | 1 | 1 |
| `workspace` | cold | 3 003.2 ms | **2 918 – 2 958 ms** | 3976, 3 skipped | 3976, 3 skipped |
| `workspace` | warm | 1 551 / 1 560 / 1 568 / 1 573 / 1 580 ms | **1 476 / 1 495 / 1 547 / 1 549 / 1 550 / 1 551 / 1 558 ms** (+ outliers, below) | 3975 from cache | 3975 from cache |
An **empty configuration reply `[{}]`** and a reply of `{"index":{"cachePath":…}}`
behave identically (94.0 vs 94.6 ms cold, 124 files both) — confirmed
explicitly, because "what does a client that says nothing get?" is the whole
point of the default change.
- `initialize` is still 2–9 ms and still does no scanning.
- **Persistence still buys ~48%** on the workspace scan (2 958 → 1 476 ms) and
~44% on the default scope (94 → 51 ms). The workspace store is still 22 MB;
the default-scope store is 1.0 MB.
- **Take 1's intermittent "warm scan at cold-scan cost" reproduced, and the
spread is wider than the clean band suggests.** An early block of four warm
runs (the §2/§3/§6 measurement sessions, taken while another process was
active) gave **1 629 / 1 658 / 1 693 / 1 945 / 2 128 ms**, and one later run
gave **3 073 ms** — against seven clean back-to-back runs of 1 476–1 558 ms.
I isolated the obvious suspect: three warm scans with
`index.logFiles: false` (1 476 / 1 550 / 1 495 ms) against three with it on
(1 549 / 1 558 / 3 073 ms) — **logging is not the cause.** The 1 476–1 558 ms
band is what this scan costs on a quiet machine; take 1's attribution of the
outliers to CPU contention stands, and so does its caveat that it is not
proven. Quote the band, not the best number.
- One structural change worth naming: **workspace scope now pays a default-scope
scan first.** The pulled `scope: "workspace"` arrives after the first scan is
already in flight at the default, so the trace is `0 files → 124 files
(40–130 ms) → 3976 files`. It costs 40–130 ms of the workspace total. Take 1
saw the same shape with a 1-file first bar instead of a 124-file one.
### 4b. The default scope now answers cross-file questions out of the box
This was take 1's headline startup finding and the change the wave made in
response. Take 1: *"on the shipped default, opening `tb.sv` gives an index of
**1 file**"* and every cross-file answer empty.
| Request at the `aes` instantiation | T1 default (= `scopeDepth 0`) | **T2 new default** | T2 explicit `scopeDepth 0` | T2 workspace |
|---|---|---|---|---|
| `definition` | **0 results**, 0.05 ms | **1 result**, 0.18 ms | 0 results, 0.09 ms | 1 result, 0.27 ms |
| `typeDefinition` | **0 results** | **1 result**, 0.06 ms | 0 results | 1 result, 0.07 ms |
| `hover` | **0 results** | **1 result** (module signature, `aes.sv:9`), 0.08 ms | 0 results | 1 result, 0.13 ms |
| `references` | **0 results** | **4 results**, 0.18 ms | 0 results | 7 results, 0.66 ms |
| `documentHighlight` | **0 results** *(and 0 at workspace too — the bug)* | **1 result**, 0.07 ms | 0 results | 1 result, 0.04 ms |
| `hover` on `.clk_i` | **0 results** | **1 result** (port decl, `aes.sv:42`) | 0 results | 1 result |
| `signatureHelp` in the port list | **0 results** | **1 signature**, 0.62 ms | 0 results | 1 signature, 0.57 ms |
| `workspace/symbol "aes"` | **0 results** | **256 results**, 3.3 ms | 0 results, 0.05 ms | 256 results, 6.6 ms |
| `completion` at a fresh line | **8 items** | **454 items**, 16.7 ms | 8 items, 0.47 ms | 483 items, 16.9 ms |
| `inlayHint` (whole file) | 0 | **0** | 0 | 4 |
The default now indexes `hw/ip/aes` — 124 files, exactly the IP block —
because `hw/ip/aes/dv/tb` raised two levels is `hw/ip/aes`. **Cross-file
answers work out of the box.** Two honest asymmetries: `references` returns 4
rather than the workspace's 7, and `completion` 454 rather than 483 — the
default sees the block, not the chip — and `inlayHint` still returns 0 at the
default (4 at workspace), so *that* one did not come along for the ride.
Explicit `scopeDepth: 0` reproduces take 1's result exactly, including all
seven "0 results" rows, which is the control this table needed.
---
## 5. The `didOpen` widen
### 5a. At `scopeDepth 0` — apples to apples with take 1
`scopeDepth 0`, `tb.sv` open, then RTL files opened one at a time; the request
sent immediately afterwards waits for the widen.
| Widening `didOpen` | T1 cold | T1 warm | T2 cold | T2 warm | Factor (warm) |
|---|---:|---:|---:|---:|---:|
| `hw/ip/aes/rtl/aes.sv` | 48.4 ms | 49.3 ms | **22.3 ms** | **22.0 ms** | **2.2×** |
| `hw/ip/kmac/rtl/kmac.sv` | 37.7 ms | 34.1 ms | **33.5 ms** | **18.1 ms** | 1.9× |
| `hw/ip/hmac/rtl/hmac.sv` | 27.0 ms | 23.9 ms | **18.2 ms** | **12.2 ms** | 2.0× |
| `hw/ip/spi_device/rtl/spi_device.sv` | 87.7 ms | 88.3 ms | **83.4 ms** | **45.7 ms** | 1.9× |
`bf9170a`'s incremental widen is intact and, at the same scope, roughly twice
as fast as take 1 measured it — 12–46 ms warm against take 1's 24–88 ms.
`spi_device` is still the ceiling, for the reason take 1 gave: its RTL
directory is much larger than the others, and the widen's cost scales with the
folder actually added.
### 5b. At the new default — the wave's one real regression
The same four jumps, at the shipped default:
| Widening `didOpen` | T2 cold | T2 warm | What it adds |
|---|---:|---:|---|
| `hw/ip/aes/rtl/aes.sv` | **1 731 ms** | **1 411 / 1 455 / 1 568 ms** | `hw/ip/aes/rtl` raised 2 = **`hw/ip`, 1 807 files** |
| `hw/ip/kmac/rtl/kmac.sv` | 3.9 ms | 2.7 ms | already inside `hw/ip` |
| `hw/ip/hmac/rtl/hmac.sv` | 3.6 ms | 2.1 ms | already inside `hw/ip` |
| `hw/ip/spi_device/rtl/spi_device.sv` | 3.6 ms | 4.0 ms | already inside `hw/ip` |
Confirmed against the progress bar directly: `didOpen aes.sv` at the default
raises one bar reading **"1807 files indexed"** and takes 1 464 ms to end.
`find hw/ip -name '*.sv' -o -name '*.svh' -o -name '*.v'` returns 1 807.
Reproduced in four independent sessions (1 411 / 1 455 / 1 568 / 1 731 ms).
Why: `scopeDepth 2` is applied per open buffer. `tb.sv` lives at
`hw/ip/aes/dv/tb`, which raised two levels is `hw/ip/aes` (124 files — the good
result of §4b). `aes.sv` lives at `hw/ip/aes/rtl`, which raised two levels is
`hw/ip` — the entire IP tree. So **the first F12 from a testbench into its own
RTL widens from one IP block to all of them**, and `bf9170a`'s incremental
widen cannot help: the new scope root *contains* the old one, so "the folders
it added" is `hw/ip` entire, and the bar re-indexes all 1 807 (no "from cache"
line, even on a warm store that held the 124).
After that one jump everything is fast again — subsequent widens are 2–4 ms
because they are already in scope, and `definition` settles at 0.12–0.47 ms.
So it is a **one-off 1.5 s freeze per session, on the single most common
navigation a Verilog user performs**, and it did not exist at `scopeDepth 0`
(where the same jump costs 22 ms). This is the clearest "got worse" in take 2.
### 5c. What the widen does to the slow requests
Take 1's clearest statement of the old root cause was that the slow requests
cost `O(files in scope)`. Same table, after opening only `aes.sv`:
| | T1 before widen | T1 after widen | T1 workspace | **T2 `depth0` after widen** | **T2 default after widen** | **T2 workspace** |
|---|---:|---:|---:|---:|---:|---:|
| `codeAction` on the instantiation | 1.8 ms | 4.5 ms | 60 ms | **4.7 ms** | 7.0 ms | **39.2 ms** |
| `prepareRename` | — (0 results) | **27.0 ms** | **2 999 ms** | **0.09 ms** | 0.08 ms | **0.07 ms** |
| `rename` | — | **93.8 ms** | **6 355 ms** | **10.5 ms** | 15.8 ms | **115 ms** |
| `workspace/symbol "aes"` | 0.04 ms (0) | 3.7 ms (256) | 6.7 ms (256) | 4.0 ms (256) | 7.8 ms (256) | 6.6 ms (256) |
`prepareRename` is now **flat in scope size** — 0.07–0.09 ms at 2 files, at 124,
and at 3 976. That is the shape the wave was aiming for. `rename` still scales
(10.5 → 115 ms), but with the fan-out rather than the scope: it is now
`O(files that mention the name)`, not `O(files in scope)`.
---
## 6. What changed and why — every delta mapped to its fix, then the detail
| Measured delta | The change that caused it | Commit |
|---|---|---|
| `prepareRename` 2 999 → **0.07 ms**, and flat in scope size | Lane A: F2 is answered from the open buffer plus the index instead of `ws.sources()`; refusal-by-refusal parity table, 4 refusals deferred to `rename` | `1029d2f` |
| `rename` 6 355 → **115 ms**, variance 2.4× → 1.13× | Lane A: `rename_sources` — declarers, reference postings, open buffers, and rung 6 `files_spelling` over the index's reference facts — instead of every in-scope file | `1029d2f` |
| anything queued behind either 2 501 / 5 079 → **0.1 / 108 ms** | consequence of the two above; the single-threaded loop is unchanged | `1029d2f` |
| `willRenameFiles` 313 → **19 ms** (§6e) | Lane A: rides `IncludeGraph::includers()` (331 includers of 3 976 files) | `1029d2f` |
| `completion` at 0–1 chars 63 → **15 ms**; ≥5 chars 5.0 → **0.6 ms**; typing a word 201 → **71 ms** | Lane B: tier-0 header slice at the terminating `;` over a bounded lex window anchored on the index span, re-planning whole-file on anything unrecognised; module table replaces a per-keystroke `workspace_symbols("")` | `61f345a` |
| `documentHighlight` 0 results → **correct results** (§7) | Lane B: `external_occurrences` over the overlay, grouped by the whole `defs()` slice — the old path answered 0 for any name the file uses but does not declare | `61f345a` |
| the default scope indexes 124 files and answers cross-file (§4b) | Lane B: `lucisv.index.scopeDepth` default `0 → 2` | `61f345a` |
| **the ~1.5 s first RTL widen** (§5b) | same change — `scopeDepth 2` raises `hw/ip/<block>/rtl` to `hw/ip` | `61f345a` |
| `codeAction` 60 → **37 ms**, comment line still 0.5 ms | already in take 1's binary as an uncommitted diff; committed here. `module_sources` (declarers, instantiation edges, `references_to` postings, open buffers) instead of `ws.sources()` | `ad27ed2` |
| widen jumps 24–88 → **12–46 ms** warm at `scopeDepth 0` (§5a) | already in take 1's binary: `widen_of` takes a scan over only the new files for pure folder adds | `bf9170a` |
| first requests answered **mid-scan** at 144 ms while the scan runs 1 544 ms (§3) | already in take 1's binary, never measured there: the scan is a value and the message queue drains between files | `172a034` |
| cold/warm workspace scan **unchanged** (3 003 → 2 958 / 1 551 → 1 476 ms) | nothing in the wave targeted the scan; the movement is inside the noise | — |
Two rows in that table are the same commit producing the wave's biggest
correctness win and its only real regression. Details below.
### 6a. `codeAction` — improved 1.5×, and still the worst thing on the hot path
Take 1 measured 46–60 ms with the `ad27ed2` fan-out subset already compiled in,
and asked for it to be memoised. It was not; take 2 measures **36–39 ms** on
the same cursor. The 1.5× is real but it is not a structural change, and the
brief's expectation of "single/double-digit ms" is only half met.
Worse, take 2 measured what take 1 could not: **the cost still tracks the
module's fan-out, linearly.** Workspace scope, warm cache, cursor on a module
instantiation, four tries each:
| Module at the cursor | Files instantiating it | First try | Repeats | Actions returned |
|---|---:|---:|---:|---:|
| `aes_reg_top` (in `aes.sv`) | 1 | 19.8 ms | 13.2 – 17.4 ms | 0 |
| `aes` (in `tb.sv`) | 6 | 39.2 ms | 36.4 – 38.2 ms | 1 |
| `prim_lc_sync` (in `aes.sv`) | 42 | 123.5 ms | 94.4 – 95.3 ms | 0 |
| `prim_alert_sender` (in `aes.sv`) | 67 | 163.6 ms | 138.8 – 139.8 ms | 0 |
| `prim_flop_2sync` (in `aon_timer.sv`) | 128 | **200.7 ms** | **184.9 – 186.2 ms** | 0 |
| *(contrast) a comment line* | — | 0.70 ms | 0.47 – 0.49 ms | 1 |
That is ~1.4 ms per instantiating file plus a ~13 ms floor, and it holds
whether the request ends up offering an action or not — the four `prim_*` rows
cost 95–186 ms to return **zero** actions. `ad27ed2`'s commit message quotes
"83 ms at a 36-file fan-out"; on the real corpus a 42-file fan-out costs 95 ms
and a 128-file one costs 185 ms. **Over §3's ~200 ms "reads as a hang" line, on
a request that fires on every cursor move, inside `prim_`-heavy RTL — which is
most of opentitan.** Take 1's suggested follow-up (memoise `module_sources` per
(module, index generation), or answer from the index instead of re-read source
text) is still the right one and is now better motivated than it was.
The early-out still works: the comment-line contrast is 0.47–0.70 ms, so
`port_action_modules` returning empty still bails before touching the
workspace.
### 6b. `prepareRename` — fixed, completely
`2 999 ms → 0.07 ms`. Take 1's push-back on the brief ("`prepareRename` is not
rare; it is what fires the instant F2 is pressed") was accepted and acted on:
Lane A answers it from the open buffer and the index. Verified over the wire:
the answer is byte-identical to take 1's —
`{"placeholder":"aes","range":{"start":{"line":44,"character":2},"end":{"line":44,"character":5}}}`
— and it is now **flat in scope size** (§5c), 0.05–0.09 ms at every scope
measured, first try and repeats alike, first request of a session included.
This is the largest single improvement in the wave and it removes take 1's
second-worst row entirely.
### 6c. `rename` — 55× faster, and the growth story is settled
`6 355 ms → 115 ms` first try; six back-to-back repeats gave **112.2 / 114.5 /
108.3 / 109.0 / 108.7 / 107.5 ms**, editing 7 files each time. Compare take 1's
dedicated 6-repeat run: 5 357 / 5 347 / 4 829 / 4 458 / 3 992 / 3 601 ms.
Note the second-order result: take 1's spread was **3 601–8 659 ms, a 2.4×
range**, which it (correctly) attributed to I/O and CPU contention. Take 2's
spread is **107.5–121.4 ms, a 1.13× range**. Reading fan-out instead of scope
did not just lower the mean, it took the variance out — the path is no longer
at the mercy of the disk.
115 ms for a workspace-wide rename of a module instantiated 6 times, producing
a correct 7-file edit set, is a good number. It is still not cancellable and
still raises no `workDoneProgress`, so take 1's structural note stands, but at
115 ms it no longer matters much.
### 6d. `completion` — 4× at the worst prefix, and the shape changed
Take 1 flagged this as a new finding and as worse than `codeAction` on the hot
path. Lane B rewrote it (header-slice tier 0 + a module table replacing a
per-keystroke `workspace_symbols("")`).
| Typed prefix | Items | T1 | T2 | Factor |
|---|---:|---:|---:|---:|
| `` (empty) | 512 | 63 – 66 ms | **14.8 – 18.6 ms** | **3.9×** |
| `a` | 512 | 58 – 61 ms | **15.9 – 19.4 ms** | **3.5×** |
| `ae` | 483 | 35 – 36 ms | 16.8 – 18.5 ms | 2.0× |
| `aes` | 482 | 34 – 37 ms | 16.1 – 17.5 ms | 2.1× |
| `aes_` | 476 | 35 ms | 15.9 – 17.4 ms | 2.1× |
| `prim_` | 339 | 16 – 19 ms | 6.1 – 6.9 ms | 2.6× |
| `clk` | 512 | 5.7 – 6.0 ms | 2.8 – 3.0 ms | 2.0× |
| `aes_reg` | 20 | 5.0 ms | **0.36 – 0.63 ms** | **9×** |
| `zzzz` | 1 | 1.4 – 2.0 ms | **0.11 – 0.13 ms** | **14×** |
The **shape** changed, and it is the more interesting result. In take 1 cost
fell steeply with prefix length (66 → 35 → 5 ms). In take 2 the first five rows
are **flat at 15–18 ms** and then fall off a cliff to 0.6 ms. Empty prefix is
no longer the worst case; `ae`/`aes`/`aes_` now cost fractionally *more* than
the empty prefix does (17 vs 15 ms). The plateau is the wire cost of the ~480
real header parses those prefixes all still require; the cliff is where the
candidate set drops below the point where that dominates.
Typing `aes_reg_top` one character at a time, completion per keystroke, hover
racing behind each:
| | take 1 | take 2 | Factor |
|---|---:|---:|---:|
| 11 keystrokes, total blocked time | **200.9 ms** | **70.6 ms** | **2.8×** |
| average per keystroke | 18.3 ms | **6.4 ms** | 2.9× |
| worst single keystroke | 61.4 ms (`a`) | **16.5 ms** (`aes_`) | 3.7× |
| first keystroke under 16 ms (frame budget) | #5 (`aes_r`, 5.3 ms) | #5 (`aes_r`, **1.3 ms**) | — |
| keystrokes 5–11 | 4.3 – 5.3 ms each | **0.41 – 1.29 ms each** | ~5× |
The `didChange` half of a keystroke was never the problem and is now cheaper
still: 0.33–0.48 ms with a barrier, and a burst of 10 `didChange` plus one
completion costs **0.74 ms** total (take 1: 2.88 ms).
**Residual, as designed:** ~15–18 ms of wire time at prefixes of 0–4 characters.
The Lane B commit predicts "opentitan wire 63–66 → 13–15 ms"; I measure
14.8–19.4 ms across two sessions, so the prediction holds with ~2 ms to spare
on the pessimistic side. Four keystrokes per identifier at 16 ms is one dropped
frame each — noticeable if you look for it, not a hang.
### 6e. `willRenameFiles` — take 1's unmeasured suspicion, now measured and fixed
Take 1 named `file_ops.rs:120`'s `for (path, text) in ws.sources()` as the same
pattern as `prepareRename`/`rename` and left it unmeasured, on the grounds that
it needs a filesystem mutation. It does not: `workspace/willRenameFiles` is a
plain request that computes an edit; the *client* performs the rename
afterwards, and mine simply discarded the answer. The opentitan checkout is
byte-identical after these runs (verified).
| | take-1 binary, workspace scope, warm | take-2 binary, same | Factor |
|---|---:|---:|---:|
| `workspace/willRenameFiles` on `aes.sv` | **312.9 ms** first, 269.9 / 286.3 repeats | **19.4 ms** first, 15.4 / 16.3 / 15.8 repeats | **16×** |
I ran both binaries back to back against the same warm store to get this, since
take 1 has no number to quote. Lane A's `IncludeGraph::includers()` rewrite
does what it says. (Renaming `aes.sv` produces a 0-file edit — nothing includes
it by name — so this measures the *search*, which is the expensive half.)
---
## 7. Non-performance findings
- **`textDocument/documentHighlight` is fixed.** Take 1: 0 results at every
position tested, at every scope, while `references` at the same positions
returned 7 and 10. Take 2: **1 result** on the `aes` instantiation and
**1 result** on the `.clk_i` port connection, at the new default scope, at
`scopeDepth 0` after a widen, and at workspace scope — with correct ranges
(`line 44 chars 2–5` and `line 49 chars 5–10`). Still 0.03–0.13 ms. Take 1's
warning ("a fast wrong answer will read as fast in any benchmark that only
times it") is what made this findable; it is now a fast *right* answer.
- **`inlayHint` still returns 4 hints at workspace scope and 0 at folder
scope** — including at the *new* default, which answers every other
cross-file question in §4b. Unchanged from take 1 and arguably now
inconsistent with its neighbours; worth a look.
- **`codeLens` still reports `"no instantiations"` for `tb`** (correct).
- **A cold workspace scan emits ~1 121 `$/progress` report notifications** (one
per ~4 files), take 1's ~994 in the same range. Same warning applies to
anyone measuring this: a naïve client is saturated by them.
- **Correction to take 1 §7 on `index.logFiles`.** Take 1 reported that
`logFiles` defaults to `true` but *"no `window/logMessage` was ever
received"*. Take 2 receives them: **4 103 `indexing: <path>` lines** on a cold
workspace scan, 124 at the default scope. I then ran the **take-1 binary**
through the same probe and it emits them too (1 message for its 1-file
default scope). So this was a take-1 measurement artifact — its folder-scope
sessions indexed one file and therefore logged one line — **not** a bug and
not something the wave fixed. Turning `logFiles` off changes the warm
workspace scan by less than the run-to-run noise (§4).
- **`implementationProvider` is still absent** from the `initialize` result and
still not measured. The advertised set is otherwise byte-identical to take
1's `caps.txt`.
---
## 8. Still slow, regressions, and surprises
Listed honestly, worst first. Three of these are new since take 1.
1. **REGRESSION — the first RTL open at the new default costs ~1.5 s** (§5b).
`scopeDepth 2` turns `hw/ip/<block>/rtl/*.sv` into a scope of `hw/ip`
(1 807 files). Opening a testbench then F12-ing into its own RTL — the most
ordinary navigation there is — freezes the server for 1 411–1 731 ms, where
the old `scopeDepth 0` cost 22 ms for the same jump. It happens once per
session and everything afterwards is 2–4 ms, but it is a real 1.5-second
hang that did not exist before, and it is a direct consequence of the fix in
§4b. The narrow version of the fix would be to clamp the raise at a
directory that looks like an IP block, or to cap the widen's file count and
fall back to the incremental path.
2. **STILL SLOW — `codeAction` at high fan-out: 185–201 ms** (§6a). Above the
"reads as a hang" line, on a per-cursor-move request, and ~2.4× worse than
the fix's own quoted estimate. `aes`'s 37 ms is the *easy* case; opentitan's
RTL is full of `prim_*` modules with 40–130 instantiators. This is now the
single worst thing on the hot path and take 1's memoisation suggestion is
unimplemented.
3. **STILL SLOW (as designed) — completion's 15–18 ms plateau at 0–4 typed
characters** (§6d). Confirmed as the predicted residual (Lane B said
13–15 ms; measured 14.8–19.4 ms). Four dropped frames per identifier typed.
Not a hang; the next tier would have to avoid the ~480 real header parses.
4. **STILL SLOW (as designed) — `rename` at ~110 ms** (§6c). Down 55×, correct,
low-variance, user-initiated. Fine as it stands; the remaining complaint is
that it is still uncancellable and silent.
5. **STILL SLOW — the cold workspace scan at ~2.9 s.** Essentially unmoved
(3 003 → 2 958 ms). It was never the wave's target, and it is once per
session per cold cache, but it is still the largest absolute number in the
document.
6. **SURPRISE — `codeAction` returns 0 actions after 95–186 ms of work** on
every `prim_*` cursor I tried (§6a). Whatever the fan-out read is for, it is
not always producing an offer; a cheap "would this even yield an action?"
pre-check would make the common case free.
7. **SURPRISE — completion's cost curve inverted** (§6d): the empty prefix is
no longer the worst case, and `ae`/`aes`/`aes_` are now *slightly* slower
than it. Small in absolute terms (15 vs 17 ms) but it means the old mental
model ("cost falls as you type") is wrong for the first four characters,
where it is now flat.
8. **Small regressions inside the noise band, listed for completeness, none
actionable:** `references` on `.clk_i` 0.48 → 0.62 ms first try (0.36–0.44 →
0.48–0.55 repeats, the one row that is consistently ~0.15 ms slower);
`documentSymbol` 0.13 → 0.16 ms; `foldingRange` 0.03 → 0.05 ms;
`workspace/symbol` repeats 5.9–6.5 → 6.6–7.4 ms. All are at or below this
harness's ±0.1 ms floor except the `workspace/symbol` repeats, which are
~13% up and worth one glance if anyone is already in that code.
9. **`inlayHint` remains empty at folder scope**, including the new default
(§7). A correctness gap, not a performance one, and the only §4b row that
the scope change did *not* fix.
---
## 9. Methodology and caveats — read before quoting any number
Take 1's caveats all still apply. The take-2-specific ones:
- **No server-side timing, again.** See §0. Every number is a client round trip
against a 0.02–0.14 ms transport floor. Nothing here is a breakdown of what
happens *inside* a slow request.
- **The comparison is binary-to-binary, not commit-to-commit.** Take 1's binary
was built from a *dirty* tree at `bf9170a` with the `code_actions` fan-out fix
uncommitted; take 2's is the packaged build of `ee1efe3`. The delta therefore
covers `ad27ed2` (as committed), `61f345a` (Lane B) and `1029d2f` (Lane A),
but *not* the `codeAction` fix in the abstract — take 1 already had it.
- **Cache control differs between the documents**, deliberately (§1). Take 2's
cold rows are genuinely cold; take 1's folder-scope "cold" row was not. The
workspace rows are comparable in both.
- **One machine, one corpus, one night.** M1 Max / 64 GB. A 2.9 s cold scan
here could be 10 s on a 4-core machine with a slower disk.
- **Page cache is hot**, and hotter than in take 1 — opentitan has now been
walked by two full measurement sessions. "Cold cache" means *lucisv's* store
was deleted, not that the OS file cache was dropped. A genuinely cold-boot
first scan will be slower than 2 958 ms, and take 2's 1.5% edge over take 1
on that row may be nothing but this.
- **The machine was quieter than in take 1, but not quiet.** No `cargo` build
of this repo ran during take 2 (the brief forbade it), which is part of why
`rename`'s variance collapsed from 2.4× to 1.13× — some of that collapse is
the fix and some is the machine, and the two are not separable here. But the
warm-scan outliers in §4 (1 629–2 128 ms early, one 3 073 ms later) show the
noise source is still present and was active during the §2/§3/§6
measurement sessions. Sub-millisecond results were stable to ±0.05 ms across
~35 sessions; multi-hundred-millisecond ones should still be read as ±20%,
and the multi-second scan rows as ±40%.
- **Repeats share a warm process.** Each "repeats" range is the 2nd–4th (or
2nd–6th) identical request in the same session. Where it mattered
(`codeAction`, `rename`, `prepareRename`) the request was issued as the first
real request of a dedicated session for the "first try" column.
- **`rename` and `willRenameFiles` were measured but never applied.** Both
return edits; the client discarded them. `git status` on the opentitan
checkout is unchanged (the one modified file is the pre-existing trailing-space
edit in `tb.sv`, mtime 2026-08-28 20:39 — an hour before take 1 began and
untouched since). It is why `textDocument/diagnostic` still returns one
`no-trailing-whitespace` item.
- **Positions were resolved from the file text at run time**, not hard-coded,
in both takes.
- **The `codeAction` fan-out counts in §6a are `grep`-derived**
(`grep -rlE '^\s*<module>( |#|$)'` over `*.sv`), i.e. a close approximation of
what `module_sources` walks, not a readout from the server. The trend is what
the table is for; the individual counts are ±a few files.
- **Nothing in the lucisv repo was built or modified by this session** except
the creation of this file. No `cargo` command was run there.
---
## 10. Raw logs
All under
`…/7b09ba01-f222-4ace-bf9a-b321331bf159/scratchpad/perf2/`
(take 1's are still in the sibling `perf/`):
| File | What |
|---|---|
| `lspclient.py` | the LSP client — take 1's, with the three changes in §1 |
| `bench.py` | phases `startup` / `nav` / `codeaction` / `rename` / `widen` |
| `bench2.py` | `blockers` (§3) / `renamegrow` (§6c) / `keystroke` (§6d) |
| `bench3.py` | `realfolder` (§5c) / `completion` (§6d), now scope-parameterised |
| `typing.py` | the per-keystroke typing simulation (§6d) |
| `widenprobe.py` | **new** — the widen at a given scope, with the bar it raises (§5b) |
| `fanout.py` | **new** — `codeAction` cost vs the module's fan-out (§6a) |
| `results.jsonl` | every measurement, machine-readable |
| `logs/startup-{default,depth0,empty,workspace}-{cold,warm*}.log` | §4 |
| `logs/nav-{workspace,default,depth0}.log` | §2, §4b |
| `logs/codeaction-workspace.log` | §6a and the pipelined test |
| `logs/rename-workspace.log`, `logs/renamegrow.log` | §6b, §6c |
| `logs/blockers-workspace.log` | §3 |
| `logs/widen-{depth0,default}-{cold,warm}.log`, `logs/widenprobe-*.log`, `logs/widenbar-default.log` | §5a, §5b |
| `logs/realfolder-{depth0,default}.log` | §5c |
| `logs/completion.log`, `logs/keystroke.log`, `logs/typing.log` | §6d |
| `logs/fanout.log` | §6a |
| `logs/willrename.log` | §6e — both binaries |
| `logs/midscan.log` | §3, the interleaved-scan probe |
| `logs/progress-ws-cold.log` | §7, the progress/logMessage census |
| `caps.txt` | full `initialize` result (advertised capabilities) |