# `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, and take 5 §P0 (TODO §60.0) corrected what some rows *meant*: see [the record schema](#the-record-schema-schema-2) below. | 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`, with and without `workspace.applyEdit`), `storagePath` cache control, `window/logMessage` capture including a `--verbose` server's own `timing:` lines, and `workspace/applyEdit` capture — timed, counted and declined | | `sites.py` | every opentitan position a phase measures, named by the *text* it wants rather than a line number | | `schema.py` | what a `results.jsonl` row means, written into the row: the version, the units, the status vocabulary, the result count, the edit fingerprint | | `harness.py` | what every phase shares: the registry, the run's configuration, the session factory, the recorder, `samples()` | | `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 | | `phases_p0.py` | take 5 §P0's phases: `execute` (what an extract/inline command really costs), `offerkinds` (the `context.only` families), `offerqueue` (leader/follower), and `scan`'s first-useful-answer half | | `phases_p1.py` | take 5 §P1's phase: `offeredit` — the first offer after a `didChange` beside the repeated offer on the unchanged buffer, at the same cursor in the same session | | `phases_p2.py` | take 5 §P2's phase: `renametrace` — eight renames, each with the server's own `timing: rename trace …` line read back off `window/logMessage` and written out as row fields (which rung selected each file, per-stage ms, per-stage **whole-file parse counts**) beside the wire time and the peak 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, plus the format-cache hits each try reported | | `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 | idle and peak server RSS after the workspace scan, and the index store's size on disk — `rss_kib` / `peak_rss_kib` / `store_kib`, never `ms` | | `execute` | §P0 | the extract and inline **commands**, run for real: `workspace/executeCommand`, the `workspace/applyEdit` the server pushes back captured and declined, the edit counted and fingerprinted | | `offerkinds` | §P0 | the seven `context.only` families at five cursors, four requests each, result counts beside every time | | `offerqueue` | §P0 | the pinmux no-offer comment as leader, an `aes` definition as follower, in separate fields | | `offeredit` | §P1 | two rows per cursor: `didChange` → `codeAction`, three times over, then three `codeAction`s on the unchanged buffer. §P1b's whole claim is about the second, so the first is never allowed to hide inside it | | `renametrace` | §P2 | eight renames — the tail, `aes`, a unique internal name, a common port name, a conflicting new name, a new name many external uses spell, a duplicate module name and a cursor on no symbol — each in its own `--verbose` session, with the engine's stage trace parsed out of the log into `trace_*` row fields and peak RSS sampled across the request. **A rename's input is not its output**: the row says how many files went in, how many bytes, which rung asked for each, and how many whole-file parses the request ran | | `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 ``` A sixth argument narrows the tree list (`… "$SP/sweep" 3 "hw/ip"`). `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. **Cache warmth is per try, not per cell** (take 5 §P0). A cold try deletes the scratch `--cache-dir` immediately before itself; a warm cell is primed by one explicit *untimed* run, whose block sits in the log behind a `--- prime (untimed, not a try) ---` marker and is counted nowhere. Before this, the cache was deleted once for the whole cold cell, so tries 2 and 3 read what try 1 had written and two of every three "cold" numbers were warm. `sweeptable.py` therefore prints the `N files from cache` each try reported and flags any cold try with a hit. Verified on `hw/ip` at 0.50.0: cold `0 / 0 / 0`, warm `30 / 30 / 30`. ## 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. ### The record schema (`schema` 2) Take 4's rows carried no `schema` key. **A row without one is schema 1**; read it with take 4's prose, where `rss.ms` held KiB, `offer-queue.ms` held a leader and a follower rather than repeats, and a request the server *rejected* was recorded as a fast success. Nothing was rewritten, so both versions live in one file; `schema.py` is the vocabulary for new rows. | Field | Meaning | |---|---| | `schema` | `2`. Absent means schema 1 — take 4's rows | | `units` | what the row's values are counted in. `ms` means the `ms` list is **latency and nothing else**; a memory row says `KiB` and carries no `ms` at all | | `status` | `ok`, `error`, `refused` or `capture` (below) | | `message` | mandatory whenever `status` is not `ok`: the server's own sentence | | `result_count` | how many things the answer carried, so a timing that moved because the *answer* moved is not read as a timing change | | `client` | the capability shape that asked: `resolveSupport`, `applyEdit`, `createFiles`. The same cursor answers differently to each | | `fresh_process` | whether each try was its own server (scan, `didOpen`, RSS, blockers) or a repeat inside one session | | `edits` / `files` / `created` | what a `WorkspaceEdit` does: text edits, files touched, files created | | `fingerprint` | sha256 over the sorted `(uri, start, end, newText)` edits, the sorted created paths and the sorted warnings — two runs' refactorings compared without copying corpus text out | | `rss_kib` / `peak_rss_kib` / `store_kib` | idle resident set, the maximum of a 50 ms `ps -o rss=` poll across the scan, and `du -sk` of the index store | | `leader_ms` / `follower_ms` | a pipelined pair, each in its own field | | `settled_ms` / `first_answer_ms` | when the scan went quiet, and when the first useful answer arrived — separate numbers, and `scan` measures them in separate sessions so the settled series stays comparable with take 4's | **The status vocabulary.** - `ok` — the server answered. - `error` — the request failed. Its time is the time of a failure, not of the operation the row is named after. - `refused` — the engine declined, in its own sentence (JSON-RPC `RequestFailed`). A refusal is a correct answer to a wrong question, but it is still not a measurement of the refactoring. - `capture` — *this client* declined an edit the server pushed at it. The corpus is read-only, so `execute` answers every `workspace/applyEdit` with `applied: false` and a capture reason. The work was done and measured; only the writing was refused, by us. **No document may quote a row whose `status` is not `ok` or `capture`** — with one exception, a row whose `expected_status` names the rejection it was built to get. The transport floor (`$/lucisvNoSuchMethod`) is the only such row: being rejected without work is the whole point of it. `schema.quotable(row)` is that rule in code. **Why `execute` exists.** An extract or inline offer carries a `command`, not an `edit`. Take 4's `refactor` phase sent every offer without an `edit` to `codeAction/resolve`; dispatch handed those to the ports resolver, which rejects an offer without its data — so their tiny times measured a refusal. `refactor` now records such an offer as belonging to `execute` and does not time it; `execute` sends `workspace/executeCommand`, times the request up to the `workspace/applyEdit` arriving (that instant is the end of the edit computation), records the reply-to-response half separately as `deliver_ms`, counts and fingerprints the pushed edit, and declines it. Nothing is written: verified after each run with `git -C status --porcelain`, and by the absence of any file an extraction said it would create.