Files

perf5-p0 — the harness tells the truth

Take 5 §P0 / TODO §60.0. Harness only: no Rust source is touched.

Goal

Before any of take 5's optimizations is measured, the measuring instrument has to mean what it says. docs/performance_take5.md §P0 names four ways tools/perf did not: phase_refactor sent extract and inline offers — which carry a command, not an edit — to codeAction/resolve, where dispatch handed them to the ports resolver and got a refusal, so their tiny times measured nothing; Session.ms discarded the response, so a request that failed was recorded as a fast success; phase_rss put idle RSS in a field called ms, which is neither a latency nor a peak; and sweep.sh::run_cell deleted the format cache once before three "cold" tries, so two of every three were warm. This stage fixes all four, adds an explicit record schema (version, units, status, result count, client shape, fresh-process flag, edit fingerprint), promotes the owner's two supplemental scratch probes into committed phases, and reproduces the owner's baseline on the unchanged 0.50.0 binary with the corrected harness so later stages have a reference measured by the instrument they will be judged with.

Assumptions

  • The corpus (/Users/guoliangchen/repo/opentitan at 0098135264) is read-only and stays at its three pre-existing modified files. Every edit a request returns is discarded, and the new execute scenario answers the server's workspace/applyEdit with applied: false.
  • target/release/lucisv{,-server} at 0.50.0 are the baseline binaries (sha256 894054128… / 27e0a0df…); no cargo command runs during a timed phase.
  • A refusal returned as JSON-RPC RequestFailed (-32803) is the engine's own sentence; any other error code is a genuine failure. That split is what distinguishes status: refused from status: error.
  • ps -o rss= polled at 50 ms is an acceptable stand-in for peak RSS on this workload; the row says so rather than claiming a kernel high-water mark.
  • The machine runs a live desktop session. Load is recorded before and after every phase and was 2.92–5.21 throughout, against the baseline's 2.92–4.59.

Handshakes

  • With lucisv-server (consumed, unchanged). The client now advertises workspace.applyEdit: true and workspace.workspaceEdit.resourceOperations: ["create", …] in the execute phase, which is what main.rs::apply_edit_support and create_files_support read. That takes the branch a real editor takes: server/client.rs::deliver pushes the edit instead of returning it. No server change is requested or needed.
  • With docs/perf/take5-baseline/ (consumed, never written). The baseline's rows are schema 1 and stay exactly as they are. Schema 2 is additive: a row without a schema key is schema 1, read with take 4's prose.
  • With docs/perf/take5-tracking.md (produced). This stage fills the P0 row's candidate identity, every "Reference — agent fills" cell it measured, and one experiment entry. Baseline cells are never overwritten.
  • Promised to P1–P4. New rows carry schema, units, status, result_count, client, fresh_process, and — where an edit exists — edits/files/created/fingerprint. No document may quote a row whose status is not ok or capture, the sole exception being a row whose expected_status names the rejection it was built to get (the transport floor). schema.quotable(row) is that rule in code.

Status / TODO

  • schema.py: schema 2 — version, units, status vocabulary, result count, normalized edits, counts(), fingerprint(), quotable()
  • harness.record() stamps and validates schema/units/status; a failing status without a message, an unknown status, or units: ms with no ms list raises instead of reaching a document
  • harness.samples() replaces Session.ms in every phase: the responses are kept, so an error is recorded as an error
  • lspclient: workspace/applyEdit captured, timed, and declined with schema.CAPTURE_REASON; workspace.applyEdit / resourceOperations capabilities; client_shape(); answered server requests no longer accumulate in the inbox
  • phases_p0.execute: command-bearing offers run through workspace/executeCommand; edit-computation and delivery halves timed separately; edits/files/created counted and fingerprinted
  • phases_new.resolve_rows: an offer with an edit needs nothing, one with only a command is routed to execute and not timed as a resolve, one with neither is resolved
  • phases_p0.offerkinds — the owner's context.only probe, promoted
  • phases_p0.offerqueue — the owner's leader/follower probe, promoted, with leader_ms and follower_ms in their own fields
  • scan reports settled time and first-useful-answer separately, in separate fresh sessions, so the settled series stays comparable
  • phase_rss: rss_kib / peak_rss_kib / store_kib, units: KiB, no ms field; peak from a 50 ms ps poll across the scan
  • sweep.sh: the scratch format cache deleted before each cold try; warm cells primed by one explicit untimed run; sweeptable.py prints the hits per try and flags a cold try with a hit
  • verified on hw/ip at 0.50.0: cold 0 / 0 / 0, warm 30 / 30 / 30
  • tools/perf/README.md documents the schema, the phases, the status vocabulary and the quoting rule
  • the baseline reproduced on the unchanged binary; tracker reference cells and the P0 experiment entry filled
  • QA — PASS, 2026-09-07 (see QA log)

Work log

2026-09-07 — dev (Opus)

Environment, checked first. lucisv 0.50.0; sha256 of target/release/lucisv 894054128495b764… and lucisv-server 27e0a0df5b77102e… — both identical to take5-baseline/metadata.json, so no rebuild was needed and none was run. Corpus git status --porcelain showed exactly the three expected files before the round and after every phase. A CI runner's cargo build --release -p lucisv (an act host executor, not this tree) was found at 100% of a core at the start of the session; no timing was taken until it exited, and load was back to 4.04–4.54 before the first timed phase.

What changed, file by file.

  • tools/perf/schema.py (new, 168 lines). The record vocabulary: SCHEMA, STATUSES, REQUEST_FAILED, CAPTURE_REASON, status_of, quotable, worst, result_count, normalized, counts, fingerprint, edit_of. status_of splits an engine refusal (RequestFailed, -32803) from a real error by code. fingerprint is sha256 over the sorted (uri, start, end, newText) edits, the sorted created paths and the sorted warnings — both changes and documentChanges shapes are read, because an extraction that creates a file cannot use the map.
  • tools/perf/lspclient.py. Session(apply_edit=, create_files=); workspace/applyEdit answered by _capture_apply_edit, which stamps the arrival instant, stores the payload and replies applied: false with the capture reason; take_applied(); client_shape(); the capability block gained workspace.applyEdit and resourceOperations; _drain_locked now moves answered server→client requests into server_requests instead of leaving them in the inbox forever.
  • tools/perf/harness.py. record() stamps schema/units/status/ fresh_process and validates; Samples/samples() keep every response and expose .row() (the ms/status/result_count/message a request row always carries); session() passes the two new capabilities; result_count now comes from schema; the old tries() was removed because samples() supersedes it and nothing else used it.
  • tools/perf/phases_p0.py (new, 304 lines). execute, offerkinds, offerqueue, and first_useful_rows() (called by scan), plus shape_of / command_of / open_and_settle, which phases_new and bench also use.
  • tools/perf/phases_new.py. resolve_rows() does the routing; refactor, tailrename, didopen, tailcompletion, hierarchy write schema-2 rows; phase_rss rewritten around rss_kib/peak_rss_kib/store_kib and a Sampler thread.
  • tools/perf/bench.py. Every phase moved to samples(); codeaction, portaction, probe record offer shapes; blockers records the leader in ms and each follower in follower_ms; scan calls phases_p0.first_useful_rows(); the transport floor carries expected_status: "error".
  • tools/perf/sweep.sh. Cold cache reset per try; warm cells primed by one untimed run behind a --- prime (untimed, not a try) --- marker; an optional sixth argument narrows the tree list.
  • tools/perf/sweeptable.py. Reads only the blocks after a --- try N --- marker (so a prime is never a trial) and prints the format-cache hits per try, flagging any cold try with a hit.
  • tools/perf/README.md. The file table, the new phases, and a "The record schema (schema 2)" section: every field, the status vocabulary, the quoting rule, and why execute exists.

The execute rows — the thing take 4 could not measure. With workspace.applyEdit and resourceOperations: ["create"] advertised, the server pushes the edit instead of returning it, and the push is timed and declined.

Site Command Status ms (executeCommand → applyEdit) edits / files / created
aes.sv 220:0–222:53 selection lucisv.extractModule capture 257.33 / 245.05–247.00 2 / 2 / 1
aes_wrap.sv 66:2 lucisv.inlineModule refused 6.58 / 5.87–6.20 —
aes_wrap.sv 66:2 (extract, also offered there) lucisv.extractModule refused 817.37 / 793.77–809.07 —

The extraction's applyEdit label is lucisv: lucisv.extractModule; deliver_ms (our applied: false → the command's response) is 0.015–0.033 ms, so essentially all of the 250 ms is the edit computation. The fingerprint is 090e92e7736e0a5a…. Nothing was written: the corpus status was unchanged and aes_extracted.sv, which the server's own warning says the edit would create, does not exist.

The phase was run twice (the second time after a cosmetic fix to the row's note and to the fingerprint of a refused row, which now records null rather than the hash of an empty edit). The second run reproduced the first: extraction 255.90 / 242.17–245.70 ms, inline refusal 6.66 / 6.07–6.49, extract refusal 820.93 / 794.46–806.51, and — the point of the fingerprint — the same 090e92e7736e0a5a… for the extraction's edit. The tracker quotes the first run; both are in the raw evidence (results.jsonl, results-execute2.jsonl).

Two findings fall straight out of these rows and are recorded, not fixed:

  • The inline cursor's extract offer costs 793–817 ms to refuse. A refusal is not a measurement of an extraction, but it is a real interactive cost of clicking an offer the engine will decline, and it is the second ~800 ms user-command path in this corpus after the tail rename.
  • Take 4's refactor rows named extract-module resolve: … and inline-module resolve: … are exactly the invalid rows §P0 describes. They are gone; the phase now records those offers as offer is a command: … | timed by the \execute` phase, not by resolve`.

Baseline reproduction. 15 phases, --tries 3, one guarded run each, in the order the baseline used, then the paired CLI experiment with the configuration order alternating per trial. 114 rows: 110 ok, 1 capture (the extraction), 2 refused (both engine sentences at the inline cursor), 1 error (the transport floor, with expected_status: "error"). Corpus unchanged after all 16 runs; no guard kill; load 2.92–5.21.

Every reference cell agreed with the owner's baseline inside the tracker's tolerance except three; all three are recorded in the tracker's experiment entry and neither number was adjusted:

  • tb.sv comment lazy: 3.80–4.79 ms against 3.22–3.50 (+27.9% on the medians). A ~4 ms row on a machine whose load band differed slightly.
  • didChange flush: 0.93–1.01 ms against 0.66–0.72 (+35.5%).
  • nav definition (+132%) and the transport floor (+10.6%) are both sub-millisecond and are not read, per the round's own rule.

The CLI cells are stronger than the timings alone: the stdout sha256 of every configuration matches the baseline's byte for byte (default, all-style, all-style minus unused-import, format cold, format warm), and the paired means are within 2.6% except default, whose baseline first trial the owner already flagged as an outlier.

Two observations worth carrying into P4 (measured, not acted on):

  • The first useful answer during a cold scan arrives in 84–86 ms with a correct result, while the same request during a warm scan takes 206–219 ms. A warm cache does not make the first answer faster here.
  • Peak RSS across the scan equals idle RSS to the KiB in all six sessions: the server's resident set rises monotonically to its idle value and there is no transient above it on this workload.

Deviations from the brief.

  • The two supplemental probes became offerkinds and offerqueue; the CLI probe stayed a scratch script (as the owner's was), because folding its --ignore unused-import cell into sweep.sh would change the committed sweep's cell set for all five trees. sweep.sh got only the cold-cache fix it was asked for, plus an optional tree-list argument.
  • scan's first-useful-answer rows are measured in separate fresh sessions from the settled rows, not the same ones. Serving a request during a scan perturbs the scan, and the settled series has to stay comparable with take 4's, which had nothing in flight. Both are scan rows and both fields are named; the perturbed settle is kept beside the first answer as settled_ms.
  • The scan phase was run twice. The first run's first-useful rows carried a hard-coded result_count: 1; that was a bug in the new code, fixed (result_counts now holds the real per-session counts), and all four workspace scan cells are quoted from the second run so they come from one consistent build of the harness. Both runs are in the raw evidence.

Gates. python3 -m py_compile tools/perf/*.py and bash -n tools/perf/*.sh clean. No Rust changed, so cargo was not run — and could not have been, mid-round.

QA log

2026-09-07 — QA (Sonnet)

Scope. Verified TODO §60.0 / docs/performance_take5.md §P0 against the working tree (tools/perf/{schema.py,phases_p0.py} new; {bench.py,harness.py,lspclient.py,phases_new.py,sweep.sh,sweeptable.py, README.md} changed) and the dev's evidence in ~/.cache/lucisv-perf/take5-p0/. Everything below was re-run independently on the same binaries under tools/guard.sh -m 8 -t 1800; my own raw evidence is in /private/tmp/.../scratchpad/qa-p0/{results.jsonl,attack*.jsonl,schema_attack.jsonl,resolve_attack.jsonl,sweep/,sweep2/}. Nothing in this section touches the dev's files or the baseline.

Environment, checked first and after. git -C /Users/guoliangchen/repo/opentitan status --porcelain showed exactly the three expected files (hw/ip/aes/dv/tb/tb.sv, hw/top_darjeeling/ip/ast/rtl/ast.sv, hw/top_earlgrey/ip/ast/rtl/ast.sv) before any run and after every phase, every attack script and both sweeps; no aes_extracted.sv or any other new file ever appeared. sha256 of target/release/lucisv (894054128…) and lucisv-server (27e0a0df5b…) matched the recorded baseline both before and after the whole session — no cargo command was run by QA. Zero guard kills across every invocation.

1. Static. python3 -m py_compile tools/perf/*.py and bash -n tools/perf/*.sh both clean. Line counts: bench.py 476, lspclient.py 471, phases_p0.py 304, phases_new.py 263, schema.py 168, harness.py 183, sites.py 122, sweeptable.py 126, sweep.sh 76, outcomes.sh 47 — all under the 500-line target. tools/perf/README.md's "The record schema" section documents every schema-2 field, the four-value status vocabulary and quotable()'s rule, matching schema.py exactly. Take-4 rows (schema 1, no schema key) in docs/perf/take5-baseline/results.jsonl and ~/.cache/lucisv-perf/take4/results.jsonl are plain JSON objects with no schema key; every schema-2 reader (harness.py, phases_new.py, bench.py) accesses fields with .get()/dict literals rather than requiring schema==2, so they remain parseable — confirmed by loading both files with json.loads line by line without error.

2. Acceptance experiments — all four reproduced independently.

  • (a) Rejected requests land as errors, never ok. Ran the baseline phase myself: the transport floor ($/lucisvNoSuchMethod) recorded status: error, code -32601: unhandled method, distinct from an engine refusal. I then hand-crafted two further bad requests through lspclient.Session directly (not through a committed phase): a textDocument/codeAction with a missing range field came back status: error, code -32602: missing field 'range'; a textDocument/rename at an out-of-bounds position came back status: refused, "lucisv: there is no symbol to rename at this position.". Both were correctly not logged as ok by record()/samples(). (One weaker probe — codeAction on a URI the server had never opened — came back ok with result_count: 0; that is the server choosing to answer an empty menu rather than reject, which is correct LSP behavior and not a harness gap: the zero count is exactly what result_count exists to make legible.)
  • (b) execute rows show a command and either an applyEdit payload or a refusal. Re-ran execute myself: extraction at aes.sv 220:0–222:53 — 258.83 / 241.39–243.00 ms (dev: 257.33 / 245.05–247.00), status capture, 2 edits / 2 files / 1 created, and the fingerprint came back byte-identical: 090e92e7736e0a5a93557d75befa65a5bea0c2f44494d71dc67e3f8d70d05835. Inline at aes_wrap.sv 66:2 refused in 6.11–6.37 ms (dev: 6.58/5.87–6.20) with the same generate-construct sentence; extract at the same cursor refused after 798.22–816.94 ms (dev: 817.37/793.77–809.07) with the same h2d_intg sentence. Corpus unchanged, no aes_extracted.sv created.
  • (c) Cold sweep tries have zero hits independently. Ran sweep.sh on hw/top_earlgrey/ip (46 files, all already needing reformatting, so it cannot exercise a warm hit) — cold 0/0/0, confirming the cold-per-try fix. Then ran the full hw/ip cell as the plan suggested as a fallback: cold 0/0/0, warm 30/30/30, byte-for-byte the number the dev reported, plus matching summary lines (445 default violations, 7751 select violations, 1772 files would reformat / 30 unchanged / 4 failed).
  • (d) RSS rows carry units, never ms. Ran rss fresh: both rows had units: "KiB", rss_kib/peak_rss_kib/store_kib populated, and no ms key present at all (checked with 'ms' in row → False). store_kib was 45404, identical to the dev's. Idle/peak: cold 527.6/529.3/531.7 MiB, warm 575.8/575.7/573.8 MiB — both within the tracker's REF band.

3. Re-taken REF cells (ten, exceeding the eight required), both numbers per cell (baseline/dev-REF vs my re-take, all on the unchanged 0.50.0 binary):

Cell Dev REF QA re-take
Pinmux comment, all families (offerkinds, None) 333.89 / 307.35–312.97 343.03 / 306.82–311.74
Pinmux comment, only: [] 81.72 / 82.27–84.11 82.29 / 82.51–84.68
Offerqueue leader/follower 339.53/339.47 (p1), 309.08/309.07 (p2), 309.73/309.72 (p3) 341.77/342.65 (p1), 309.59/309.57 (p2), 308.65/308.63 (p3)
aes_reg_top lazy offer (codeaction) 30.64 / 22.72–24.42 31.15 / 22.51–24.59
state_q tail rename 813.44 / 778.77–782.13; 5/2/0; fp b39defb21265… 823.09 / 779.96–788.93; 5/2/0; fp identical b39defb212655f29e68c0e15b88dda405d2779a24c4b522a1798b6f44c9a04f7
aes rename 167.60 / 140.46–142.13; 14/9/0; fp fa7e31c78382… 168.84 / 140.58–141.67; 14/9/0; fp identical fa7e31c78382176d5f96d661228ce82328df8bc77bd6d8575dd38717814cb26c
Connect-missing-ports resolve 171.37 / 165.77–167.45 171.995 / 165.26–166.15
Cold workspace scan (3 fresh) 2860.12–2868.45 2828.26–2848.97 (baseline 2830.30–2853.06)
Warm workspace scan (3 fresh) 1346.02–1352.80 1312.68–1361.91 (baseline 1322.24–1344.03)
didopen pinmux row (3 fresh) 119.01–131.85 109.12–135.15

All ten agree with the dev's REF within the tracker's tolerance (the two fingerprinted rows match to the full 64-hex-character hash, which is the strongest form of agreement available). The scan and didopen rows are fresh-process ranges and show the expected extra spread of a 3-sample wall-clock measurement on a shared desktop, but stay centered on the same values.

4. Schema attacks — all four raised, plus two negative controls. Called harness.record() directly (schema_attacks.py):

  • units="ms" with no ms field → raised ValueError: row 'a' says ms but carries none.
  • status="bogus" → raised ValueError: status 'bogus' is not one of (...).
  • status="error"/"refused"/"capture" with no message → each raised ValueError: a '<status>' row must carry its message.
  • Negative controls (a well-formed error row with a message, and a KiB row with no ms) did not raise, confirming the checks are precise, not overzealous.

resolve_rows() (resolve_attack.py): called it with a fake Session whose .request() raises AssertionError if invoked, and a synthetic command-only action ({"command": {"command": "lucisv.extractModule", ...}}, no edit). resolve_rows never called .request() — it recorded the offer as "... offer is a command: ...", note: "timed by the execute phase, not by resolve", confirming a command-only offer can never land as a fast ok resolve.

5. The three "disagrees beyond tolerance" rows — re-taken, and stable, not noise.

  • tb.sv comment, lazy (codeaction, "comment line, lazy"): my re-take was 7.73 / 4.42–5.42 ms, still elevated over baseline's 3.22–3.50 and, if anything, further from it than the dev's 3.80–4.79. Same direction, same order of magnitude as a ~1–5 ms row on this desktop.
  • didChange flush: my re-take was 1.35–1.64 ms (first 2.19), against baseline's 0.65–0.72 and the dev's 0.93–1.01 — again elevated, and by more than the dev's own reading.
  • Format-cold peak RSS: the dev's paired CLI run reported 246.5 MiB against baseline 202.2. My independent sweep.sh run on hw/ip (not the paired CLI script, but the same cell) reported 239 MB peak RSS for format --check cold — same elevated band, nowhere near the baseline's 202.2.

All three disagreements reproduce independently and in the same direction on a second, unrelated invocation, which argues for a real (if small, machine/load-dependent) effect rather than a one-off noisy sample. Correctly left unadjusted by the dev; nothing here changes that.

6. Traceability. Sampled 20 numbers from the tracker's REF cells and the P0-2026-09-07 experiment entry and searched ~/.cache/lucisv-perf/take5-p0/*.jsonl for each. All 20 trace to the raw evidence; the handful that did not match on a first plain-text grep (e.g. 333.89, 245.05, 2860.12, 535.2) turned out to be the tracker's 2-decimal rounding of a longer float (333.8862499804236, 245.04641597741283, 2860.1173329807352, 548032.0/1024 = 535.19 MiB) — confirmed by loading the exact row and comparing the full-precision value. Nothing was actually missing.

Verdict: PASS.

No findings. All four §P0 acceptance criteria hold under independent re-execution; ten re-taken REF cells (two with byte-identical 64-character fingerprints) agree with the dev's numbers within tolerance; the schema and resolve_rows attacks behave exactly as specified, including the negative controls; the three named disagreements reproduce in the same direction on a second run, supporting "real, not noise, and correctly left unadjusted"; traceability is complete once rounding is accounted for. Corpus, binaries and guard were clean throughout. No fix was needed in tools/perf.

Review

2026-09-07 (lead). Accepted. Read schema.py, resolve_rows, the sweep change, the tracker's REF cells and experiment entry, both logs.

  • The four §P0 defects are fixed the way the plan asked and nothing else was touched: no production code, the baseline evidence untouched, schema 2 additive over schema 1. record() refusing a malformed row and quotable() as the quoting rule in code are the right place for the discipline — a document cannot quote a rejection by accident.
  • The reference re-take is the useful result: every row P1/P2 will be judged against was re-measured by the instrument that will judge them, on the same binary, and agrees with the owner's baseline inside tolerance except three sub-5 ms rows that both dev and QA reproduce in the same direction. Left unadjusted, correctly.
  • Two new facts feed later stages: the extract command at the inline cursor spends ~800 ms producing a refusal (P1 measures it after the selector reuse, P2 owns it if it is scope work); and the first useful answer during a warm scan is slower than during a cold one (206–219 vs 84–86 ms), a P4a lead.
  • Deviation accepted: the CLI probe stays a scratch script beside sweep.sh rather than changing the committed sweep's cell set.