Files
lucisv/tools/perf/README.md
T

19 KiB
Raw Blame History

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 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
phases_r1.py the review round's §R1 phases: actionprofile (the timing: codeaction … stage split at three cursors × four request shapes), ruleablation (one row per default-on rule, lucisv.lint.select pushed between rows) and snapshotrss (idle RSS at 1 / 10 / 100 buffers, each asked for quick fixes so every one holds a lint snapshot)
phases_p4.py take 5 §P4a's phases: scanprofile (the startup breakdown, one row per traced scan), scanwait (the first useful answer with that session's own trace beside it) and scanserve (a definition every 200 ms for as long as the scan runs, with the mid-scan/settled answer coherence check)
phases_r3b.py the review round's §R3b phase: renamewarn — four renames' warning sentences, read off window/logMessage verbatim, because a rename's warnings never travel in the WorkspaceEdit and so are in no phase's fingerprint
phases_r4.py the review round's §R4 phases: scanload / scanloadcold (a definition every 100 or 250 ms of wall clock, a fixed number of them, with the server's own publication split in the row), scanloadcross (the same load at a cursor the open buffer's folder cannot answer) and scanloadprobe (one cell, for checking the probe itself)
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 -- <command> 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 <opentitan> 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

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 codeActions 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
scanprofile §P4a the startup breakdown, from the server's own timing: scan <n> stages/counts/memory lines: workspace cold and warm, the default scope, scopeDepth 0, and 1 / 10 / 100 open buffers. One row per traced scan — a session at a configured scope pays two (the startup scan runs at the default settings and the pulled scope asks for another), and adding them together would be wrong
scanwait §P4a §P0's first-useful-answer rows, re-run under --verbose, so the trace of the very session that answered sits in the row: when the first publish landed, how many publishes there were, how long the config round trip took
scanserve §P4a a textDocument/definition every 200 ms for as long as the scan is still saying anything: the mid-scan latency distribution, and mismatched_answers — non-empty answers that named somewhere the settled index does not, which must be 0 (the coherence contract of docs/features/index-scope/README.md)
actionprofile §R1b one --verbose session per cursor, four request shapes each — the first menu of the session, three repeats on the unchanged buffer, a definition queued behind it, and the first menu after each of three didChanges — with the server's own timing: codeaction … line parsed into trace_* fields. Three groups per line: flush{…} is the debounced Document rebuild and the diagnostics publish inside it, rebuild{…} splits that rebuild into the stages Document::new runs — lex, parse, defines, analyze, external, lines — plus the publish the flush does with the result and the documents it built (TODO §63.2), and action{…} is the handler. The groups are siblings, never nested: phases_p2.parse_trace flattens one level of name{…}, which is how all three arrive as trace_flush_* / trace_rebuild_* / trace_action_* row fields with no parser change. A request that lints nothing logs no line, which is why the queued rows say how many the follower logged
ruleablation §R1b which rules the pinmux quickfix menu's milliseconds are in: one warm session, lucisv.lint.select pushed to a single rule per row by didChangeConfiguration (a selection change rescans nothing), the unrestricted control taken first and last so session drift is visible rather than blamed on a rule
snapshotrss §R1a idle and peak RSS with 1 / 10 / 100 open buffers, each sent one quickfix-only codeAction so that every open document holds a lint snapshot — the memory bound of docs/features/perf5r-lint-snapshot/README.md. rss_kib / peak_rss_kib, never ms
renamewarn §R3b every lucisv: warning sentence four renames say, in order, written into the row as titles and compared line by line between labels. renametrace hashes a rename's edits; its warnings are window/logMessage notifications and are in no fingerprint, so a reuse that kept every edit and dropped a sentence would otherwise pass
scanload §R4 the controlled form of scanserve. A textDocument/definition every 100 and every 250 ms of wall clock, counted from the session's start and independent of the responses — a fixed number of them, so both binaries are offered exactly the same load and a faster one shows it as answers arriving after settle rather than as requests never sent. Warm cache, 1 / 2 / 11 / 101 open buffers, three fresh sessions a cell, plus a quiet control (the same cell, no requests) so a settle time that moved because of the load can be told from one that moved anyway. Each row carries every request's own wait (median and max, and the same two over the mid-scan subset), how many were answered before settle, mismatched_answers and unsettled_answers, the settle time, tick_jitter_ms (how a reader checks the arrival discipline the row claims) and, from the session's own --verbose trace, publishes, published and the four publish_* stages
scanloadcold §R4 scanload with the index store deleted before every session. A separate phase because a cold cell under this load is a ten-second session, and eight of them do not fit inside the 1 800-second guard — splitting the run is the answer to that, raising the guard is not
scanloadcross §R4 scanload at a cursor whose target is outside the open buffer's own folder (tl_if, declared in hw/dv/sv/tl_agent), which is the case the empty-answer rule of docs/features/perf5r-publication/README.md is for: in a server without that rule it is answered [] at the head publish, and the row says what the rule costs those requests and what it buys
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

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

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
stages / counts / memory §P4a's three trace lines, parsed into dicts: per-stage ms, per-stage work counts, and the sizes the finished scan left resident. ms on such a row is the scan's own total, and settled_ms is every try's wall clock
config_wait_ms / mismatched_answers how long workspace/configuration took to come back, and how many mid-scan answers disagreed with the settled index
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 <opentitan> status --porcelain, and by the absence of any file an extraction said it would create.