Files
lucisv/docs/performance_take5_review.md
T

20 KiB
Raw Blame History

Performance take 5 — independent implementation review

Reviewed 2026-09-08 at 0.51.0, 126a6bcdac99e940534c87bce94a5269cdc53ae4 against release 0.50.0. The implementation delivers the major menu, rename, CLI and warm-memory improvements. Retain those changes. The original performance targets are only partly met: large-file lint work, startup's first useful answer, and broad refactor analysis remain material costs.

Status (2026-09-09): implemented as TODO §61 — R3a (§61.1), R1a/R1b (§61.2), R2a/R2b (§61.3), R4 (§61.4), R3b/R3c (§61.5); results in docs/perf/README.md's 2026-09-08 review-round entry and the tracker's follow-up queue. This is a measurement and planning review as written; no production code was changed by it. The completed implementation ledger remains intact; its new independent-review section tracks follow-up experiments. Raw evidence and reproduction instructions accompany this report. The original rationale is in the take 5 plan.

Measurement basis

  • Both release servers were checked with guarded cargo build --release --locked before timing. The reference is a preserved clean checkout at 3bd55acb983776bef0bf035d7ec7bc894d4bbd04; its crates/ source is identical to the original report's bbdbfe9. Latest means this local checkout, with no remote fetch.
  • Both binaries ran through the same current schema-2 harness, sequentially, with phase order alternating which binary went first. No Cargo build or other review benchmark overlapped timed runs. Every corpus run used the 8 GiB / 1,800-second guard.
  • OpenTitan is 00981352642fb65ef2b6c47143a0f6bb31fd4a97, with the same three pre-existing modifications. LSP edits were captured/discarded; CLI used checks. Corpus status and the three modified-file hashes were checked around the LSP phases. CLI diagnostic stdout is compared byte for byte.
  • Request cells normally contain one first request plus three repeats; the table uses the median of those three repeats. Scan, RSS, didOpen and first-after-change cells use three trials; queue cells use three pipelines. Cold/warm means persistent index cache, not OS page-cache eviction. Three samples do not establish p95/p99 or statistical significance.
  • Fresh trace runs are attribution evidence, separate from the paired non-verbose latency comparison. Scan stage fields describe the first traced session; rename stage fields describe the last traced request. Neither is a median stage profile.

Paired results

Milliseconds unless another unit is shown. Lower is better. Action requests use resolving clients; execution requests advertise applyEdit/create-file support but reject the write after capturing it.

Workload 0.50.0 reference 0.51.0 review Assessment
Pinmux comment, all action families, unchanged 300.4 25.0 12.0× faster; still above the original 16 ms aspiration
Definition queued behind that action 311.7 24.2 Blocking is greatly reduced
Pinmux comment, quickfix only 81.5 23.1 Explains almost all remaining all-family cost
Pinmux comment, empty family filter 82.4 0.06 Unrequested work is gated out
Pinmux comment, first action after change 413.9 135.9 3.0× faster; still a visible edit-time pause
Lazy action at aes_reg_top instance 25.5 5.1 Roughly 5× faster
Organize-imports offer 13.5 4.1 Discovery improved
Large state_q rename 795.1 398.3 Approximately 2× faster; two edited files
Ordinary aes rename 144.1 92.4 1.56× faster; nine edited files
Resolve connect-missing-ports 170.4 134.3 Expensive click remains, with some reuse benefit
Resolve expand wildcard 72.7 55.4 Same output fingerprint
Extract-module edit computation 249.5 150.3 Same captured edit; two files, one creation
Extract from inline-site selection, refused 811.7 804.9 Essentially unchanged; not a successful extraction
Inline generate-containing module, refused 6.1 6.4 Same refusal, already cheap
Whole-workspace scan, cold cache 2,908.6 2,907.3 No material change; 2.3 s target remains unmet
Whole-workspace scan, warm cache 1,381.4 1,117.9 19% lower; still above 1.0 s
First useful definition, cold cache 85.6 286.8 201 ms slower in this comparison
First useful definition, warm cache 214.7 328.2 113 ms slower in this comparison
Idle RSS, warm workspace (MiB) 574.4 419.0 27% lower
Idle RSS, cold workspace (MiB) 531.2 496.9 Modest median reduction; candidate range 491–539 MiB
didOpen pinmux → definition 119.8 118.1 Large-file open cost persists, without a clear regression
CLI hw/ip default check 430 440 Similar
CLI hw/ip error/warning/style check 660 490 26% lower; identical diagnostic bytes
Same CLI style check, ignoring unused-import 480 510 Small wall-time movement; no demonstrated improvement

The fresh paired numbers support the implementation ledger's principal claims. Small differences from its 24 ms menu / 388 ms rename / 1.04–1.10 s warm scan numbers are not new code changes: this is another measurement of the released implementation. The startup latency target was already recorded as missed in P4b3; it should remain a visible follow-up, even though the implementation stages are closed.

Startup throughput and responsiveness must be judged separately

The scanserve probe sends another definition 200 ms after the preceding response. The worst observed wait fell from 2,594 to 337 ms cold, and 933 to 328 ms warm. Non-empty mid-scan answers matched the settled answer in both versions.

The candidate served 13 requests per cold session rather than 3, and 5 per warm session rather than 3. Its harness-observed session completion time was about 4.93 s cold / 2.02 s warm, versus 3.31 s / 1.77 s for the reference. These are request-perturbed session measurements, including the probe's sleeps and completion detection. They are not a controlled fixed-request-count scan regression: the responsive server is doing more request/publication work. They identify a follow-up measurement: fixed offered load, publication count/time, request latency, and scan completion together.

CLI and format-cache interpretation

CLI style user CPU fell from a median 3.48 to 2.44 seconds, while the control without unused-import stayed around 2.4 seconds. Diagnostic counts stayed 445 default, 7,751 style, and 7,734 style without unused-import, with matching stdout hashes across versions. This supports removing duplicated package-census work. The candidate's style-vs-no-unused-import wall difference is smaller than run variability; do not call a negative difference a negative-cost rule or claim an exact 5 ms contribution from this rerun.

A candidate-only formatter sanity check took 0.67 s cold / 0.68 s warm. This raw corpus has 1,772 files that would change, 30 unchanged files, and four safe-format failures. Only the 30 unchanged files hit the warm check cache. That is a low-hit-rate workload, not evidence that the successful unchanged-file cache stopped working. No old/new formatter speed claim is made from it.

Causes and next implementation plan

1. Reduce large-file action and edit-time work

Measured cause: refactor-only filters are now effectively transport-bound, while quickfix still costs 23 ms out of a 25 ms all-family menu. lucisv_server/src/lint.rs::fixable still calls lint_with on every request. The fence memo and parsed selector reuse work as intended; they do not memoize lint results. The first action after a change costs 136 ms versus roughly 24 ms on repeats. That additional latency includes dirty-buffer work; subtracting the cells is an attribution clue, not an isolated parse measurement.

Plan:

  1. Trace configuration/waiver loading, dirty-buffer flush, lint execution, fence filtering and action serialization separately on the pinmux case. Include first request, unchanged repeat, first request after one-character edit, and navigation queued behind each.
  2. Define a reusable lint-result snapshot through the existing diagnostics/server-lint contract in topo.md, keyed by every dependency that affects the result: document content/revision, effective rules/configuration, external waiver state, tab width and project/index inputs. The previous agent deliberately deferred this because invalidation is not just document version. Write the dependency/invalidation table before implementing a cache.
  3. Let diagnostics and quickfix discovery consume a matching result; recompute when the snapshot does not match. Bound retained data and avoid adding a second unbounded analysis cache. Preserve the shared fence authority and execute-time validation.
  4. Profile the dirty-buffer stage independently. If it dominates the 136 ms edit case, a lint cache alone cannot fix it. Reuse work only when it matches the current text, and preserve didChange-before-request ordering. Consider parser/semantic work reuse only after stage measurements justify it.

Gate: proposed follow-up target ≤16 ms unchanged pinmux menu and queued definition; first-after-edit should improve from 136 ms without stale diagnostics, stale edits, or higher retained memory. A changed buffer, configuration, waiver, dependency file, close/reopen, and UTF-16 range tests must force the correct fresh result. Do not claim the first-edit target achieved from repeat-only samples.

2. Recover first-answer latency without restoring duplicate startup scans

Measured cause: the fresh warm first-answer trace returned a definition in 325.4 ms. It spent 205.0 ms discovering the workspace and 92.3 ms opening the cache. Together those stages account for about 91% of that latency. The configuration reply arrived in 0.73 ms, so the two-second fallback timeout is not the cause of this normal-case delay.

Workspace::begin_scan in state/mod.rs obtains the full path list before stepping it. The first step opens the persistent store, and requests wait for the open buffer's raised-folder head to be published. The reference could answer from its earlier 124-file folder scan; the candidate avoids that extra scan but pays whole-workspace discovery first. The new ordering also prevents the empty initial answers observed during implementation. Keep that correctness improvement.

Plan:

  1. Measure walk/config-ignore handling, repeated metadata calls for the size cap, path sorting, cache container load, and local-folder indexing independently. First experiment: reuse metadata already obtained by the core walker for the cap instead of querying it again, if that preserves walk semantics. This crosses lucisv_core::walk and server scope discovery; record the handshake before changing its interface.
  2. Explore handing the raised-folder work to the scan before remaining workspace discovery finishes. Deduplicate paths and facts, preserve configured scope, exclusions, filelists and size caps, and publish index/candidates/includes/overlays coherently. This must not become two complete scans or answer from only the open file.
  3. If cache opening remains a first-answer barrier, measure a bounded local-record loading design before proposing a persistent-format change. Compare the memory and total-start cost; an extra cache format is not justified by latency alone.
  4. Use the existing startup and scan-interleave contracts in topo.md, including staging, head_owed, rescan ordering, and the large-neighbourhood fallback. Test configuration replies arriving before/after didOpen, late/no reply, unsaved buffers, multiple folders, a root-level file, and dependencies outside the first folder.

Gate: all first-definition results must match the settled target, not merely be non-empty. Proposed next milestone: ≤200 ms warm and cold for this cursor, then work toward the reference's 86/215 ms cold/warm behavior; warm total scan ≤1.0 s, with no loss of the RSS reduction. Report cold and warm independently.

3. Reduce analysis cost in large rename and slow refusals

Measured cause: the latest traced state_q rename selects 238 files / 4.55 MB, edits two, and performs 240 whole-file parses: 238 for the initial scope and two for the edited after-index. One repeated trace attributes 229.2 ms to scope indexing, 74.3 ms to verification, 50.9 ms to warnings, 14.1 ms to selection, and 12.4 ms to edit collection. Before/after verification no longer reparses unchanged watched sources. That is the implemented win; the initial scope is now the largest cost.

The broader candidate-only, verbose probe exposes worse tails. These are current costs, not a paired regression claim:

Rename request Repeat median Result Selected files
Common port clk_i → clk_ix 3,455 ms Edit returned 3,976
cipher_alert → heavily used clk_i 2,884 ms Refused, meaning would change 3,976
Duplicate module rstmgr_por 2,200 ms Refused, ambiguous declaration 3,976
Comment cursor with no symbol 2,192 ms Refused, no symbol here 3,976

The no-symbol trace performs 3,975 whole-file parses and spends 1,904 ms in scope indexing before a 0.1 ms locate refusal. server/rename.rs calls ws.sources() when it finds no old name, and vlog_refactor::rename::renaming builds the scope before locate. This is a concrete avoidable-work candidate. Normal clients often issue the already-cheap prepareRename first, so frequency should be tracked separately from severity.

The whole-process RSS sampled during these requests also matters: the common-port rename peaks at 1.76 GiB, versus 572 MiB for the smaller tail rename. The no-symbol refusal reaches 894 MiB. These are 50 ms sampled peaks, not allocation totals or paired memory regressions. The lower idle RSS does not eliminate transient analysis memory.

Plan:

  1. Measure parsing, semantic analysis, index assembly, and allocation within the 229 ms initial scope stage. The current aggregate is not enough to select a parser versus index optimization.
  2. Evaluate a request-local path that accepts already analyzed, content-matching facts for open documents and immutable cached facts for closed files. Reuse must be tied to the selected source bytes, retain unsaved-buffer precedence, and rebuild cross-file resolution for the candidate workspace. A persistent decoded analysis cache needs a memory budget before it is justified.
  3. Profile the remaining 51 ms warning pass separately. Preserve warning meaning, order and deduplication; optimize scanning/allocation rather than dropping warnings to meet the number.
  4. Keep the existing source-selection set as the correctness reference. The implementation found 133 indirect files among the 238 selected. A file without the target declaration may still provide a container needed for hierarchical resolution. Two edited files do not justify selecting two input files. Any narrower selector must reproduce whole-scope edits, refusals, warnings and resolution on the hierarchy/bind/macro adversarial cases, including handshake 33's token-census coverage.
  5. Instrument the still-805 ms refused extraction at the aes_wrap inline-site selection. extract::Plan::plan builds a scope before computing the selection's safety checks; determine which prerequisite work is avoidable for a proven refusal. Put any cheap preflight in the refactor engine so the server does not become a second authority on what is safe. Preserve the exact refusal, not an optimistic edit.
  6. As a small first experiment in this lane, add an engine-owned preflight for a provably empty cursor before workspace source materialization. Preserve error precedence (invalid new name, out-of-scope/unavailable file, then cursor refusal), current-buffer semantics and the exact engine message. Do not treat all prepareRename failures or unresolved references as the same cheap case. Extend to duplicate-module refusals only with evidence that the index used is current and authoritative. Proposed no-symbol gate: ≤16 ms and zero closed-workspace parses, with identical refusals on the scoped test matrix.

Gate: use 398 ms large rename and 805 ms refused extraction as the current baselines. A useful first rename experiment should materially reduce scope work (proposed ≥20% wire-time improvement) at bounded peak RSS; the original <200 ms rename aspiration remains a stretch target. Compare ordinary, common-port, collision, macro/bind, hierarchical-tail and fallback cases, not only the successful two-file edit. Never widen verifier forgiveness for speed.

4. Optimize scan work after separating quiet and busy cases

Measured cause: a traced quiet warm scan spends about 217 ms in final index absorb, 200 ms decoding facts, 114 ms constructing candidates, 110 ms reading source text, and 48 ms in lookup, in addition to discovery/cache opening. It writes zero new bytes and performs zero compactions, so another unconditional-compaction fix is no longer the next lever. Cold parsing is 1.70 s of a 2.88 s traced scan.

While requests arrive, server/index.rs::answer_what_is_waiting publishes a staged prefix per burst; state/mod.rs::publish_scan merges the index and candidates, updates includes and refreshes open overlays. More responsiveness means paying this work more frequently. Publication cost is a source-backed hypothesis for the busier session; this review does not have a CPU breakdown of those busy publications.

Plan: first add a fixed-arrival-rate probe and record publication/overlay costs alongside queue latency and scan completion. Then test incremental table construction or reduced duplicate publication work, preserving the coherent-prefix contract. Benchmark one, ten and many open buffers. Optimize quiet-scan decode/merge allocations only after an allocation profile identifies duplication. Pursue cold parser throughput separately if the 2.3 s target still matters after interactive stalls are addressed.

Gate: retain correct mid-scan answers and the current memory reduction; improve request waits and completion under the same offered load. Do not improve scan throughput by withholding useful answers until completion, or report fewer served requests as a speedup.

Verification and limits

All paired sampled edit fingerprints, action titles/shapes, result statuses, refusal messages and warnings matched, apart from scanserve intentionally collecting more responses from the more responsive candidate. Both sampled renames and three resolved edits match the reference. Extract execution produced the same captured edit. Inline execution in this corpus case refused in both versions; successful inline execution was not independently established by that timing row.

Both releases returned one definition in all six paired first-answer trials. The candidate returned one in six additional traced trials. Scanserve found zero non-empty-answer mismatches. Its check permits empty interim answers, so it is not a complete proof that every possible startup request is useful. This is a performance review of representative workloads, not exhaustive correctness certification or a full allocation/leak study. The eager non-resolving high-fan-out client path was not remeasured; its previous non-hot classification is retained.

Independent focused correctness checks passed: 8 startup tests, 7 scan-order tests, and 3 after-index tests. The first startup test invocation incorrectly requested a library target for the binary-only server crate; the corrected invocation passed. No guard limit was hit. A full workspace test/clippy run was not repeated for this documentation-only review. LSP-phase one-minute load samples ranged from 2.82 to 6.00, so small differences should not be treated as statistically established regressions. Original-baseline and final corpus modified-file hashes match.