Files
lucisv/docs/performance.md
lucio 89186a8eaa
ci / checks (push) Successful in 53s
ci / corpus (push) Successful in 21s
docs: move performance and topology notes
2026-08-29 13:29:57 -07:00

26 KiB
Raw Permalink Blame History

lucisv-server LSP performance against opentitan

Measured 2026-08-28 on the real opentitan checkout, driving the real server binary over stdio with a scripted LSP client. Every number below is a client-observed round trip on a monotonic clock (time.perf_counter), which is what the editor — and therefore the user — actually experiences.


0. Read this first: the binary is not instrumented

The brief said the binary at …/scratchpad/lucisv-server-instrumented emits window/logMessage lines of the form timing: <method> answered in X ms. It does not. Verified three ways:

  • strings -a on the binary finds no timing, answered, handled in, elapsed, took, or ms literal anywhere.
  • Over ~20 sessions the client received zero window/logMessage notifications, despite index.logFiles defaulting to true.
  • shasum -a 256 shows the binary is byte-identical to /Users/guoliangchen/repo/verilogrustformatter/target/release/lucisv-server (ce7e15db473e81f420a247ca463085c22262b28815d6edb8345da04ecadfe7cc), i.e. it is the ordinary release build, copied. crates/lucisv_server/src/perf.rs is an #[ignore]d in-process test module, not protocol instrumentation.

I could not rebuild (the brief forbids running cargo in the repo, since another agent is editing it concurrently). So there is no server-side handling column below. In its place I measured a transport baseline: an unknown request method ($/lucisvNoSuchMethod), which the server rejects without doing any work. Its round trip is 0.02–0.33 ms (median ≈ 0.05 ms across all sessions). Everything above ~0.5 ms is therefore server work, not framing, and for an isolated request client round trip ≈ server handling + 0.05 ms. The one thing the missing instrumentation costs us is a breakdown inside a slow request; the queue-blocking numbers in §3 are client-observable by construction and are unaffected.


1. Environment and provenance

Machine Apple M1 Max, 10 cores, 64 GB RAM
OS macOS 27.0 (build 26A5421a)
Date 2026-08-28, ~21:50–22:15 local
Binary lucisv-server 0.14.0, Mach-O arm64, 4,120,288 bytes, sha256 ce7e15db…dfe7cc
Repo HEAD bf9170a — "A scope widen indexes the folders it added, not everything again"
Working tree at build time dirty: lucisv_server/{ports,state}.rs, vlog_refactor/{lib,ports}.rs modified 21:43:09–21:43:29; binary linked 21:47:27. The in-progress code_actions fan-out fix (ws.module_sources() replacing ws.sources()) is therefore compiled into this binary. ports.rs was touched again at 21:55 (tests) — after the build.
Corpus /Users/guoliangchen/repo/opentitan @ 0098135264 — 3979 .sv/.svh/.v files; the server indexes 3976, skips 3
Scenario file hw/ip/aes/dv/tb/tb.sv (100 lines); module aes instantiated at line 45 (0-based 44, col 2); .clk_i port connection at line 50; aes defined at hw/ip/aes/rtl/aes.sv:9
Client scratchpad/perf/lspclient.py + bench.py / bench2.py / bench3.py / typing.py

Cache state is controlled per run via workspace/configuration → {"index":{"scope":…,"cachePath":"<temp dir>"}}. "Cold" = the cache directory was rm -rf'd immediately before. "Warm" = the directory carries a previous session's store (23 MB for the full workspace).


2. Summary table — worst first

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.

Action First try Repeats Verdict
textDocument/rename on aes (edits computed, not applied) 6 355 ms 3 601 – 8 659 ms very slow
— anything queued behind that rename (definition / hover / documentSymbol) 5 079 ms — very slow
textDocument/prepareRename on aes (this is just pressing F2) 2 999 ms 1 723 – 2 597 ms very slow
— anything queued behind that prepareRename 2 501 ms — very slow
Workspace scan, cold cache (didOpen → 3976 files indexed) 3 003 ms — acceptable (once)
Workspace scan, warm cache (3975 of 3976 from cache) 1 551 ms 1 548 – 1 580 ms acceptable
textDocument/completion at 1 typed character (512 candidates) 61 ms 34 – 66 ms slow (fires per keystroke)
textDocument/codeAction on the aes instantiation 60 ms 46 – 49 ms slow (fires per cursor move)
— definition pipelined behind that codeAction 53 ms 47 – 58 ms slow
definition immediately after a widening didOpen (spi_device.sv) 88 ms 88 ms (2nd session) slow-ish
definition immediately after a widening didOpen (aes.sv) 48 ms 49 ms (2nd session) acceptable
definition immediately after a widening didOpen (kmac, hmac) 38 / 27 ms 34 / 24 ms acceptable
Typing 11 characters (aes_reg_top), completion each keystroke 201 ms total — 18 ms/keystroke avg
workspace/symbol "aes" (256 results) 6.7 ms 5.9 – 6.5 ms fine
textDocument/completion at ≥5 typed characters 5.3 ms 4.0 – 5.0 ms fine
initialize → response 2.0 – 8.0 ms — fast
textDocument/hover on aes 1.35 ms 0.07 – 0.16 ms fast
textDocument/codeAction on a comment line (contrast) 0.93 ms 0.50 – 0.91 ms fast
didChange flush (measured with a foldingRange barrier) 0.75 ms 0.25 – 0.32 ms fast
textDocument/references on aes (7 hits, incl. declaration) 0.61 ms 0.39 – 0.72 ms fast
textDocument/signatureHelp inside the port list 0.61 ms 0.48 – 0.53 ms fast
textDocument/definition on aes 0.49 ms 0.11 – 0.18 ms fast
textDocument/references on .clk_i (10 hits) 0.48 ms 0.36 – 0.44 ms fast
textDocument/inlayHint (whole 100-line file) 0.36 ms 0.21 – 0.25 ms fast
textDocument/documentSymbol 0.13 ms 0.13 – 0.21 ms fast
textDocument/semanticTokens/full 0.16 ms 0.12 – 0.13 ms fast
textDocument/typeDefinition on aes 0.15 ms 0.09 – 0.10 ms fast
textDocument/diagnostic (pull) 0.13 ms 0.04 – 0.07 ms fast
textDocument/selectionRange at the instantiation 0.12 ms 0.08 – 0.09 ms fast
textDocument/documentHighlight (see §7 — returns nothing) 0.09 ms 0.03 – 0.12 ms fast
textDocument/codeLens 0.10 ms 0.03 – 0.07 ms fast
textDocument/documentLink 0.09 ms 0.05 – 0.08 ms fast
textDocument/foldingRange 0.03 ms 0.05 – 0.07 ms fast
textDocument/definition / hover on .clk_i 0.05 ms 0.03 – 0.07 ms fast
transport baseline (unknown method — does no work) 0.02 – 0.33 ms — floor

textDocument/implementation is not advertised by this server (implementationProvider absent from the initialize result) and was not measured. Advertised and measured: typeDefinition, typeHierarchy, callHierarchy, diagnostic (pull, with workspaceDiagnostics: true), inlineCompletion, linkedEditingRange, documentOnTypeFormatting, willSaveWaitUntil.


3. The queue-blocking analysis — this is the owner's pain

The server runs a single-threaded request loop: one message is taken off stdin, answered to completion, and only then is the next one read. Nothing is cancelled, nothing is answered out of order, nothing runs on a worker. So the latency a user feels for request R is not R's own cost — it is R's cost plus the un-finished cost of everything the editor already sent.

I measured this directly. Each slow request was sent, and then — with no wait, same TCP-less pipe, back to back — three requests a real editor fires on every cursor move. All four were timed from the same t0:

Sent first (the blocker) Its own cost definition behind it hover behind it documentSymbol behind it
codeAction on the aes token 60.0 ms 60.0 ms 60.1 ms 60.3 ms
prepareRename on aes 2 500.7 ms 2 500.7 ms 2 500.9 ms 2 501.0 ms
rename on aes 5 079.1 ms 5 079.1 ms 5 079.2 ms 5 079.3 ms
workspace/symbol "aes" 9.7 ms 9.7 ms 9.7 ms 9.8 ms

The same three requests, sent alone into an idle server in the same session, cost 0.11 ms, 0.07 ms and 0.13 ms.

Read the amplification:

  • definition behind codeAction: 52.7 ms first try (47.4–58.2 ms repeats) vs 0.11 ms alone — ~480×. This is the one the brief asked for by name. The dedicated pipelined test (codeAction then definition, neither waited on) gave 52.65 / 58.13 / 47.36 ms for the codeAction and 52.72 / 58.18 / 47.38 ms for the definition riding behind it — the definition's answer lands 0.02–0.05 ms after the codeAction's, i.e. the queue is strictly serial and the follower pays the leader's bill almost exactly.
  • definition behind prepareRename: 2 500.7 ms vs 0.11 ms — ~22 000×.
  • definition behind rename: 5 079.1 ms vs 0.11 ms — ~46 000×.

Why this matters in an editor rather than in a benchmark: VS Code does not send one request at a time. Moving the cursor emits codeAction + documentHighlight + inlayHint + codeLens; typing emits didChange + completion + signatureHelp + diagnostic. Every one of those lands behind whatever is currently executing. So a 3-second prepareRename is not a 3-second F2 — it is a 3-second freeze of hover, go-to-definition, highlight, and the completion popup, and any keystroke typed during it is not even parsed until it ends.

Two structural consequences worth stating plainly:

  1. The absolute number matters more than the ratio. workspace/symbol amplifies a follower by ~90× too, but 9.7 ms is invisible. The threshold is roughly the frame budget: anything under ~16 ms is free, 16–100 ms is noticeable on a cursor move, and anything over ~200 ms reads as a hang.
  2. codeAction and completion are the only slow requests on the hot path. rename/prepareRename are user-initiated; codeAction fires whether or not the user wants a lightbulb, and completion fires on every character.

4. Startup and scan, per scope and cache state

didOpen tb.sv → the last $/progress end, followed by 1.5 s of silence. (Naïvely waiting for the first end is wrong: the server raises three progress bars in a row — a 0-file one, a 1-file one for the opened buffer, and only then the real workspace scan under token lucisv-index-2. My first pass made exactly this mistake and reported a 102 ms workspace scan.)

Scope Cache didOpen → settled Files indexed
folder (the default) cold 102.2 ms 1
folder (default) warm 101.1 ms 1
workspace cold 3 003.2 ms 3976 indexed, 3 skipped
workspace warm 1 551 / 1 560 / 1 568 / 1 573 / 1 580 ms 3976, 3975 from cache, 3 skipped
  • initialize itself is 2.0–8.0 ms and does no scanning; the scan is kicked off by the first didOpen.
  • The real scan begins ~300 ms after didOpen (the two trivial bars occupy the first ~105 ms), so cold wall-clock from didOpen to a usable workspace index is ~3.0 s and warm is ~1.6 s.
  • Persistence buys ~1.45 s (48%) on this corpus. The store is 23 MB.
  • Once the bar ends the index is genuinely ready: definition answers correctly at 0.16–0.25 ms immediately, and is no better after a further 1 s idle. There is no post-bar background settling to wait for.
  • Three runs (rename-workspace 2 741 ms, blockers 3 004 ms, renamegrow 2 987 ms) showed warm scans at cold-scan cost while still reporting "3975 from cache". Five clean back-to-back runs afterwards were all 1 551–1 580 ms. I attribute the outliers to CPU contention (another agent was building this repo on the same machine during the session), not to a cache miss — but it is not proven, and if warm scans are intermittently 2× it is worth a look.

The default scope is the headline startup finding, and it is not a performance finding. IndexScope::Folder with scopeDepth: 0 (crates/lucisv_server/src/settings.rs) walks only the open file's own directory. hw/ip/aes/dv/tb/ contains exactly one file. So on the shipped default, opening tb.sv gives an index of 1 file, and:

Request at the aes instantiation folder scope (default) workspace scope
definition 0 results, 0.05 ms 1 result, 0.49 ms
typeDefinition 0 results 1 result
hover 0 results 1 result (module signature)
references 0 results 7 results
workspace/symbol "aes" 0 results 256 results
completion at a fresh line 8 items 483 items
signatureHelp in the port list 0 results 1 signature

Folder scope's uniformly sub-0.1 ms timings are therefore not a speed result — they are the cost of answering nothing. Any comparison of folder vs workspace latency that ignores this is meaningless.


5. The didOpen widen (item 7) — the fix holds

Folder scope, tb.sv open, then RTL files opened one at a time. Each open widens the scope to a new folder, which the server indexes; the request sent immediately afterwards waits for that work. Measured on both a cold and a warm cache directory:

Widening didOpen definition behind it (cold cache) (warm cache)
hw/ip/aes/rtl/aes.sv 48.4 ms 49.3 ms
hw/ip/kmac/rtl/kmac.sv 37.7 ms 34.1 ms
hw/ip/hmac/rtl/hmac.sv 27.0 ms 23.9 ms
hw/ip/spi_device/rtl/spi_device.sv 87.7 ms 88.3 ms

Verified: this is the post-fix regime. The brief records 120–169 ms before bf9170a and 12–44 ms after; three of the four jumps land in 24–49 ms. spi_device at ~88 ms is above the quoted band, which is expected rather than alarming — hw/ip/spi_device/rtl/ is a much larger directory than the others, and the widen now indexes the folders it added, so its cost scales with the folder actually opened. Worth recording as the current ceiling for a single jump.

The cache makes almost no difference here (48.4 vs 49.3 ms), which makes sense: the widen's cost is walking and parsing a directory the store has entries for only if a previous session in the same cache dir already widened into it.

After the widen, and after the index settles, everything is fast again (definition 0.18/0.04/0.03 ms).

But the widen changes the cost of the slow requests too, because sources() now returns more files. Folder scope, after opening only aes.sv:

before widen after widen workspace scope
codeAction on the instantiation 1.8 ms 4.5 ms 60 ms
prepareRename — (0 results) 27.0 ms 2 999 ms
rename — 93.8 ms 6 355 ms
workspace/symbol "aes" 0.04 ms (0 results) 3.7 ms (256) 6.7 ms (256)

This is the clearest statement of the root cause: the slow requests cost O(files in scope). 2 files → 27 ms. ~200 files → 94 ms. 3976 files → 3 000 ms.


6. Root causes

6a. codeAction — already fixed in this binary, still 60 ms

The brief predicted ~3 s on the instantiation and asked me to verify. It is 46–60 ms, not 3 s, because the fix described as "in progress this session" is compiled into the binary I was given (sources modified 21:43, binary linked 21:47). The diff replaces

let sources = ws.sources();                        // every in-scope file

with

let modules = vlog_refactor::port_action_modules(&doc.text, offset);
if modules.is_empty() { return Vec::new(); }
let sources = ws.module_sources(&path, &modules);  // that module's fan-out

in crates/lucisv_server/src/ports.rs::code_actions, plus a sources_at() helper doing the same for the addPort / removePort / propagatePorts commands.

That the contrast case is 0.5–0.9 ms (comment line, port_action_modules returns empty and the function bails before touching the workspace) while the instantiation case is 46–60 ms shows the early-out works and the residue is the fan-out read itself: aes is instantiated ~6 times workspace-wide, so module_sources still reads and parses those files on every cursor move onto the instantiation. 60 ms per cursor move is still four frames, and §3 shows it is charged to whatever the editor sent next.

Suggested follow-up (not implemented — out of scope for this measurement task): memoize module_sources per (module, index generation), or answer codeAction from the index rather than from re-read source text.

6b. prepareRename — 2.5–3.0 s, and it is not "user-initiated-rare"

crates/lucisv_server/src/rename.rs:30:

let target = vlog_refactor::prepare_rename(&ws.sources(), &path, offset)?;

ws.sources() reads and returns every file in scope — 3976 files at workspace scope. prepareRename is a read-only request whose entire job is to answer "is this token renameable, and what range/placeholder?". It returns {"placeholder": "aes", "range": {line 44, chars 2–5}} — information available from the open buffer alone. It does not need the workspace.

I want to push back on the brief's framing here. The brief labels the rename machinery "user-initiated-rare" and expected slowness to be acceptable. prepareRename is not rare and it is not what the user thinks of as "doing a rename" — it is what fires the instant F2 is pressed, before the rename box even appears. 2.5–3.0 s of a wholly frozen server, on a keypress that has not yet committed to anything, is the second-worst result in this report and by §3 it takes hover, definition and highlight down with it. I'd rate it the most fixable serious problem here, and more urgent than codeAction: the fix is narrower (answer the range from the buffer; only consult the workspace if the token turns out to be a cross-file symbol) and the payoff is larger.

6c. rename — 3.6–8.7 s, genuinely rare, genuinely expensive

rename.rs:47 has the same ws.sources() call and then computes edits across the workspace (7 files edited for aes). 3.6–8.7 s is bad but this one really is a deliberate, infrequent, "I asked for a big thing" action, and it produces a correct workspace-wide edit set. Acceptable if it reported progress and were cancellable, which it currently is not (workDoneProgress is not raised for it, and the single-threaded loop cannot service $/cancelRequest while busy).

Correction to an earlier reading: my first rename run showed 6 355 → 7 486 → 8 659 ms and looked like monotonic growth (a leak). A dedicated 6-repeat re-run showed 5 357 → 5 347 → 4 829 → 4 458 → 3 992 → 3 601 ms — decreasing. There is no growth; the spread is machine noise (see §8). Range across all runs: 3 601–8 659 ms, which is itself a 2.4× spread and a sign of how much this path is at the mercy of I/O and CPU contention.

6d. completion — 34–66 ms per keystroke, and it is a NEW finding

Flagging this loudly: this was not in the brief's list of known-slow items, and on the hot path it is worse than codeAction.

Completion cost tracks the number of candidates before the 512-item truncation, i.e. it is worst exactly when the user has typed the fewest characters — the beginning of every identifier:

Typed prefix Items returned Round trip
`` (empty) 512 63–66 ms
a 512 58–61 ms
ae 483 35–36 ms
aes 482 34–37 ms
aes_ 476 35 ms
prim_ 339 16–19 ms
clk 512 5.7–6.0 ms
aes_reg 20 5.0 ms
zzzz 1 1.4–2.0 ms

Typing the identifier aes_reg_top one character at a time, with a completion request per keystroke (what VS Code's 24×7 IntelliSense does) and a hover racing behind each one:

keystroke  1 'a'            completion  61.44 ms   hover-behind-it  61.46 ms  (512 items)
keystroke  2 'ae'           completion  36.13 ms   hover-behind-it  36.15 ms  (483 items)
keystroke  3 'aes'          completion  35.36 ms   hover-behind-it  35.39 ms  (482 items)
keystroke  4 'aes_'         completion  34.92 ms   hover-behind-it  34.94 ms  (476 items)
keystroke  5 'aes_r'        completion   5.34 ms   hover-behind-it   5.35 ms  ( 35 items)
…
keystroke 11 'aes_reg_top'  completion   4.27 ms   hover-behind-it   4.27 ms  (  1 items)
→ 11 characters cost 200.9 ms of server time (18.3 ms/keystroke average)

Note clk → 512 items in 6 ms versus `` → 512 items in 64 ms: the returned count is capped at 512 either way, so the cost is not in building or serialising the result. It is in scanning/filtering the candidate set, and the broader the prefix the more of the 3976-file symbol table is walked. A prefix index (or an early bail once 512 matches are found, if the ordering permits) would flatten this.

The didChange half of a keystroke is not the problem: measured alone with a foldingRange barrier it is 0.25–0.75 ms, and a burst of 10 didChange notifications followed by one completion cost 2.88 ms total. The flush is cheap; the completion is not.

6e. file_ops.rs:120 — same pattern, unmeasured

for (path, text) in ws.sources() in crates/lucisv_server/src/file_ops.rs:120 serves workspace/willRenameFiles. The server advertises willRename with a ** folder filter, so renaming any folder in the VS Code explorer will pay the same full-workspace read. Not measured (it needs a file-system mutation, and the brief forbids touching the opentitan checkout), but it is the same ws.sources() shape as §6b/§6c and should be on the same follow-up list.


7. Non-performance findings worth surfacing

  • textDocument/documentHighlight returns 0 results at every position tested — on the aes instantiation and on the .clk_i port connection, at both folder and workspace scope, before and after the widen, even though documentHighlightProvider: true is advertised and references at the same positions returns 7 and 10 hits respectively. It is fast (0.03–0.12 ms) because it is doing nothing. This looks like a functional bug, not a perf issue, but a fast wrong answer will read as "fast" in any benchmark that only times it.
  • inlayHint over the whole file returns 4 hints at workspace scope and 0 at folder scope, and codeLens reports "no instantiations" for tb (correct — nothing instantiates the testbench).
  • A cold workspace scan emits ~994 $/progress report notifications (one per 4 files). Harmless for a real editor, but it saturated my first measurement client and made a 3-second scan look like a 70-second one. Worth knowing before anyone else measures this.
  • index.logFiles defaults to true but no window/logMessage was ever received in any session. Either the default is not being honoured or the log is gated on something the pulled configuration did not supply.

8. Methodology and caveats — read before quoting any number

  • No server-side timing. See §0. Every number is a client round trip. The transport floor is 0.02–0.33 ms, so for isolated requests the two are within noise of each other, but a slow request's internal breakdown is not available and nothing in this document should be read as one.
  • One machine, one corpus, one afternoon. M1 Max / 64 GB is a fast laptop. A 3 s cold scan here could be 10 s on a 4-core machine with a slower disk.
  • Page cache is hot. opentitan had been walked repeatedly by earlier sessions before I started; "cold cache" above means lucisv's index store was deleted, not that the OS file cache was dropped. A genuinely cold-boot first scan will be slower than the 3 003 ms reported.
  • The machine was not quiet. Another agent was editing and building this repo concurrently, by design of the task. This is the most likely explanation for the three anomalous 2.7–3.0 s "warm" scans in §4 and for the 2.4× spread in rename. The sub-millisecond results are unaffected (they were stable to ±0.05 ms across ~20 sessions); the multi-hundred-millisecond ones should be read as ±30%.
  • Repeats share a warm process. Each "repeats" range is the 2nd–4th identical request in the same session, so it reflects whatever the server memoised on the first. Where that matters (codeAction, rename) I ran the request as the first request of a dedicated session to get a genuinely cold first try; that is what the "first try" column reports.
  • rename was measured but never applied. textDocument/rename returns a WorkspaceEdit; the client discarded it. The opentitan checkout is unmodified (verified: no writes, only didOpen of existing files).
  • Instrumentation overhead is nil — there is none to have. Client overhead (JSON encode/decode, framing) is inside the 0.05 ms transport baseline.
  • Positions were resolved from the file text at run time, not hard-coded, so the numbers stay attached to the aes instantiation and the .clk_i port connection even if the file shifts.
  • tb.sv carries one pre-existing local edit — a trailing space on line 44, git diff against 0098135264, mtime 20:39, an hour before this session began and not made by this measurement. It is why textDocument/diagnostic returns a no-trailing-whitespace item. Nothing in the checkout was written by these runs.

9. Raw logs

All under /private/tmp/claude-501/-Users-guoliangchen-repo-verilogrustformatter/7b09ba01-f222-4ace-bf9a-b321331bf159/scratchpad/perf/:

File What
lspclient.py the LSP client (framing, config/progress replies, timing helpers)
bench.py phases startup / nav / codeaction / rename / widen
bench2.py phases blockers (§3) / renamegrow (§6c) / keystroke (§6d)
bench3.py realfolder (§5 post-widen table) / completion (§6d table)
typing.py the per-keystroke typing simulation (§6d)
results.jsonl every measurement, machine-readable
logs/startup-{folder,workspace}-{cold,warm*}.log §4
logs/nav-{workspace,folder}.log §2 whole-document and cursor batteries
logs/codeaction-{workspace,folder}.log §6a and the pipelined test
logs/rename-workspace.log, logs/renamegrow.log §6b, §6c
logs/blockers-workspace.log §3 queue-blocking table
logs/widen-folder-{cold,warm}.log, logs/realfolder.log §5
logs/completion.log, logs/keystroke.log, logs/typing.log §6d
logs/progress-ws-cold.log the multi-bar progress trace behind §4's note
caps.txt full initialize result (advertised capabilities)