# `tools/perf` — the lucisv performance harness Take 1's, take 2's and take 3's measurement clients all lived in a scratch directory and all three are gone; take 3's numbers had to be re-derived from take 2's *prose*. This directory is the fix. Everything a performance round needs is here, in Python 3 with **no third-party packages**, so it runs from a clean checkout given an opentitan path and a pair of binaries. Written for take 4 (`docs/performance_take4.md`, TODO §58). Take 5 reuses it. | File | What it is | |---|---| | `lspclient.py` | framed JSON-RPC over a `lucisv-server` child process: the `workspace/configuration` pull answered per session, per-session client capabilities (with and without `codeAction.resolveSupport`), `storagePath` cache control, `window/logMessage` capture including a `--verbose` server's own `timing:` lines | | `sites.py` | every opentitan position a phase measures, named by the *text* it wants rather than a line number | | `harness.py` | what every phase shares: the registry, the run's configuration, the session factory, the recorder | | `bench.py` | the command line, and the phases that reproduce take 3's tables | | `phases_new.py` | the phases for what 0.44–0.49 added: the new offer sites, §49's surface, §46's `didOpen` fix, `moduleHierarchy`, index size and RSS | | `sweep.sh` | the timed CLI sweeps (`format --check`, `check`) over five trees, `/usr/bin/time -l` | | `sweeptable.py` | those logs → the document's §7 Markdown table | | `outcomes.sh` | the untimed per-file outcome runs, for the release-to-release outcome diff | ## The rules every run obeys - **Everything goes through the guard.** `tools/guard.sh -m 8 -t 1800 -- ` wraps every server session, every `lucisv` invocation and every `cargo` build. `sweep.sh` and `outcomes.sh` wrap their own children; wrap `bench.py` yourself. A guard kill is a finding — report the command and the limit, never raise it. - **The corpus is read-only.** The formatter cache goes to a scratch `--cache-dir`, the index cache to a scratch `storagePath` (`bench.py --storage`), and every edit a request returns (`rename`, `codeAction/resolve`) is discarded by the client. Check `git -C status --porcelain` after every phase. - **No `cargo` command runs anywhere while a timed phase is running**, and the machine's load average is noted before and after each phase. - **Three tries per row**, first try and repeat range both reported. ## Running a phase ```sh SP=/tmp/perf # scratch: caches, logs, results.jsonl OT=$HOME/repo/opentitan tools/guard.sh -m 8 -t 1800 -- python3 tools/perf/bench.py nav \ --server target/release/lucisv-server \ --label 0.49.0 --opentitan "$OT" \ --storage "$SP/caches/0.49.0" --out "$SP/results.jsonl" --tries 3 ``` Every phase takes the same arguments. `--label` is what tells two binaries apart in `results.jsonl`; run each phase once per binary. | Phase | Document section | What it does | |---|---|---| | `baseline` | §0 | `initialize`, and the transport floor (`$/lucisvNoSuchMethod`, rejected without work) | | `verbose` | §0 | four `codeAction` shapes, each with and without `--verbose`, so the server's own `timing:` line sits beside the wire | | `scan` | §4 | the (scope × cache state) startup matrix: `default`, `{"index":{}}`, `scopeDepth 0`, `workspace`, cold and warm | | `scopes` | §4b | what each scope *answers* at the `aes` instantiation — counts, not just times | | `nav` | §2 | the cheap per-cursor requests at workspace scope, one dedicated session each | | `flush` | §2 | the `didChange` flush, measured with a `foldingRange` barrier | | `codeaction` | §6a | the five fan-out cursors (1 / 6 / 42 / 67 / 128 files), lazy and eager | | `portaction` | §6 | the one opentitan cursor that offers a port refactoring: offer and `codeAction/resolve` | | `refactor` | §6b | the offer sites 0.44–0.49 added — expand `.*`, organize imports, inline module, port actions, and an ANSI header as the contrast — plus the extract-module *selection* | | `rename` | §6c | `prepareRename` and `rename` on `aes` | | `tailrename` | §6c | §49's hierarchical tail: a variable renamed at its declaration, named through an instance from another file | | `blockers` | §3 | the queue-blocking analysis: a slow leader, then the three requests an editor fires on every cursor move | | `widen` | §5 | the `didOpen` widen at `scopeDepth 0` and at the default scope, cold and warm | | `didopen` | §5/§46 | `didOpen` → the request behind it, workspace scope, the four files the perf README's 2026-09-05 table used | | `diagnostics` | §2 | the publish after a `didChange` (≈150 ms of it is the debounce) | | `completion` | §6d | the typed-prefix curve | | `tailcompletion` | §6d | completion after an instance head and a `.` | | `hierarchy` | §6 | `lucisv/moduleHierarchy`, the snapshot the DUT sidebar consumes | | `rss` | §6 | server RSS after the workspace scan, and the index store's size on disk | | `probe` | — | ad-hoc: `--probe FILE:LINE:CHAR` (0-based) prints what a cursor offers. This is how `sites.REFACTOR_SITES` was found | ## The CLI sweeps ```sh tools/perf/sweep.sh ~/.cache/lucisv-baselines/lucisv-0.49.0 0.49.0 "$OT" "$SP/sweep" 3 python3 tools/perf/sweeptable.py "$SP/sweep" --labels 0.49.0,0.43.0,0.39.0 ``` `sweep.sh` writes one log per (label, tree, command, cache state) holding the three tries' `/usr/bin/time -l` blocks; `sweeptable.py` reads them all and prints the table plus the summary line each run reported, so a timing that moved because the *work* moved is not mistaken for a timing change. ## The outcome diff ```sh tools/perf/outcomes.sh ~/.cache/lucisv-baselines/lucisv-0.43.0 0.43.0 "$OT" "$SP/outcomes" tools/perf/outcomes.sh ~/.cache/lucisv-baselines/lucisv-0.49.0 0.49.0 "$OT" "$SP/outcomes" diff "$SP/outcomes/0.43.0.format.txt" "$SP/outcomes/0.49.0.format.txt" ``` Untimed, `--no-cache`, paths rewritten relative to the corpus root and sorted, so two runs differ only where a per-file *outcome* did. Every difference is either explained by a TODO section or is a finding. ## `results.jsonl` One JSON object per row: `phase`, `label`, `row`, `ms` (the try list, first try first), and whatever else the phase knows — `n` (a result count, a file count, a byte count), `titles`, `note`. Nothing in the document may quote a number that is not in this file or in a `sweep.sh` / `outcomes.sh` log.