Every tracked file that can carry a comment (880 of them) now opens with "Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with "Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com", in the file's own comment syntax. No behaviour change: the diff outside the version bump and changelogs is comment lines only. - tools/stamp_author.py: writes the lines; idempotent, `--check` lists what is missing. Headers go under a shebang and under Markdown front matter. - Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the LICENSE files (already carry the copyright line). - tools/linux_check.sh: --help reads its header from line 3, now that the author line sits under the shebang. - tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
659 lines
36 KiB
Markdown
659 lines
36 KiB
Markdown
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
|
||
|
||
# perf-first-after-edit
|
||
|
||
TODO §63.2 — N1 of the 0.52.0 review (`docs/performance_052_review.md`,
|
||
item 3 and next action 3).
|
||
|
||
## Goal
|
||
|
||
The first request after a one-character edit in a 40 267-line generated
|
||
file cost **113.6 ms** on 0.52.0, against 0.23 ms for the same request
|
||
repeated on an unchanged buffer. The lint snapshot (review round §R1a)
|
||
cannot help a fresh revision: what remains is the debounced `Document`
|
||
rebuild `answer_request` performs before any handler runs, the
|
||
diagnostics publish that lints the new revision, and the menu's own
|
||
stages. This round splits that flush into the stages a reader can act on,
|
||
then makes the **fresh-revision work itself cheaper** — no cache of
|
||
anything across revisions — with the AST, the diagnostics and the menu
|
||
byte-identical. Target: ≥ 15 % off the cell, stretch < 95 ms, the
|
||
unchanged-repeat cell and the other `offeredit`/`offerkinds` rows within
|
||
noise, peak RSS not up.
|
||
|
||
## Assumptions
|
||
|
||
- The pinmux cell is the worst realistic shape, not the typical one: a
|
||
1 237 143-byte generated register file, 193 816 tokens, one buffer
|
||
open, workspace scope, 3 975 files indexed. Everything here is measured
|
||
on it; a 400-line hand-written file pays the same work in microseconds.
|
||
- `Document::new` is a pure function of (text, index): the same text
|
||
against the same index must give the same tokens, tree, defines,
|
||
semantics, external resolutions and line index. Every change in this
|
||
round is checked against that, file by file, over the corpus and
|
||
opentitan (see Parity).
|
||
- `vlog_parser::tokenize` is all-or-nothing and its output is a value,
|
||
not a rendering: two builds agree on token kind, text, line, column,
|
||
span, `blank_before` and every attached comment, or they differ.
|
||
- The measurement machine is shared with nothing else while a phase runs
|
||
(`tools/perf/README.md`'s rules), and every number below is a median.
|
||
|
||
## Handshakes
|
||
|
||
- **`lucisv_server ──▶ vlog_parser`** — unamended. `tokenize`,
|
||
`parse_tolerant` and `parse_source_tolerant` keep their signatures;
|
||
`Document::new` calls them exactly as before. No public `vlog_parser`
|
||
item changed name, type or behaviour, so nothing this lane did is a
|
||
contract change for the formatter, linter, refactor or CLI either.
|
||
**Nothing is owed to the lead here.**
|
||
- **`verbose-timing ◀──▶ tools/perf`** — *amended, and this needs a
|
||
`docs/topo.md` line the lead owns.* The `timing: codeaction …` line
|
||
(`crate::lint_trace`) grows a **third top-level group**, `rebuild{…}`,
|
||
beside `flush{…}` and `action{…}`: `lex`, `parse`, `defines`,
|
||
`analyze`, `external`, `lines`, `publish` (ms each) and `documents`
|
||
(how many `Document`s the flush built). Groups stay siblings — never
|
||
nested — because `tools/perf/phases_p2.py`'s `GROUP` regex flattens one
|
||
level only; `phases_r1.py` therefore picks the new fields up with no
|
||
change, as `trace_rebuild_*` row fields. Pinned by
|
||
`lint_trace::tests::the_rebuild_group_names_every_stage_beside_the_other_two`.
|
||
- **`docs/perf/README.md`** — not this lane's file. The entry it wants is
|
||
in "For `docs/perf/README.md`" below, for the lead to paste.
|
||
|
||
### Requested `docs/topo.md` amendments (the lead's file)
|
||
|
||
1. The `verbose-timing ◀──▶ …` handshake row (§2.7): add that the
|
||
`timing: codeaction` line carries a third group, `rebuild{…}`, whose
|
||
fields are the flush's `Document`-rebuild stages, and that the three
|
||
groups are siblings by contract (the harness flattens one level).
|
||
2. The `lucisv_server/src/state.rs` file row: `Document::new`'s six
|
||
derivations are individually traced through `crate::lint_trace`, so a
|
||
stage added to or removed from that constructor wants a `Rebuild`
|
||
variant beside it.
|
||
|
||
## Status / TODO
|
||
|
||
- [x] the flush split in `lint_trace` (`Rebuild`, `Rebuilt`, `rebuild()`,
|
||
`saw_document()`), the `rebuild{…}` group on the trace line, and
|
||
the 0.53.0 numbers taken **before** any behaviour changed
|
||
- [x] change 1 — the lexer's two phases fused (no `Vec<RawTok>`)
|
||
- [x] change 2 — `Parser::skip`, the non-cloning `bump` for the 217 call
|
||
sites that threw the token away
|
||
- [x] change 3 — the operator table's first-byte test
|
||
- [x] parity: token stream + parse diagnostics + whole AST + symbol table
|
||
digested per file over 4 807 files (corpus + opentitan), 0 differ;
|
||
`format --stdout` byte-identical over corpus (860) and over
|
||
opentitan (3 947); diagnostics and the all-family menu on the
|
||
pinmux buffer identical before and after
|
||
- [x] paired `offeredit` / `offerkinds` / `flush` / `diagnostics` /
|
||
`rss` against a 0.53.0 server built from 1b8723c, order alternated
|
||
— **−19.2 % on the cell, the ≥ 15 % gate met and the < 95 ms
|
||
stretch met at 88.3 ms**
|
||
- [x] QA
|
||
|
||
## Work log
|
||
|
||
### 2026-09-12 — measure first: the flush split
|
||
|
||
`crate::lint_trace` already split a traced request into
|
||
flush / config / build / lint / fence / serialize. The flush was one
|
||
number (`flush{wall=…}`), so "the dirty-buffer stage dominates" was as
|
||
far as the 0.52.0 review could attribute the cell. Added:
|
||
|
||
- `Rebuild` (7 stages: `lex`, `parse`, `defines`, `analyze`, `external`,
|
||
`lines`, `publish`), `Rebuilt` (their milliseconds plus a `documents`
|
||
count) and `rebuild(stage, work)` / `saw_document()` — the same
|
||
thread-local, one-`Cell`-read-when-off discipline the module documents,
|
||
and *not* routed through `IN_FLUSH`: a rebuild belongs to the rebuild
|
||
whichever half of the request runs it.
|
||
- `crates/lucisv_server/src/state/mod.rs:119` — `Document::new`'s six
|
||
derivations each wrapped at the call.
|
||
- `crates/lucisv_server/src/server/diagnostics.rs:57` — the publish
|
||
inside `flush_dirty` wrapped as the seventh, so the flush group's
|
||
`config`/`build`/`lint`/`fence` are readable as *inside* it.
|
||
- `Trace::line()` prints `rebuild{…}` as a **sibling** of `flush{…}` and
|
||
`action{…}`; `Trace::is_empty` counts it, so a request that only
|
||
rebuilt still logs a line.
|
||
|
||
`tools/perf` needed no code change: `phases_r1.py` parses the whole line
|
||
through `phases_p2.parse_trace`, which flattens any top-level `name{…}`
|
||
group, so the seven stages arrive as `trace_rebuild_*` fields on every
|
||
`actionprofile` row. `tools/perf/README.md`'s `actionprofile` row now
|
||
says so.
|
||
|
||
**The 0.53.0 numbers** (HEAD 1b8723c plus this instrumentation and
|
||
nothing else; `actionprofile`, pinmux-comment, "first codeAction after a
|
||
didChange", three tries; evidence
|
||
`~/.cache/lucisv-perf/63-2/split-0530.jsonl`):
|
||
|
||
| | ms |
|
||
|---|---:|
|
||
| wire latency | 122.6 / 123.0 / 101.4 |
|
||
| **flush wall** | **100.0** |
|
||
| ├ `rebuild lex` | **29.1** |
|
||
| ├ `rebuild parse` (the token clone is inside it) | **25.6** |
|
||
| ├ `rebuild publish` | 22.2 — of which `flush lint` 22.0 |
|
||
| ├ `rebuild analyze` | 10.1 |
|
||
| ├ `rebuild external` | 4.8 |
|
||
| ├ `rebuild lines` / `defines` | 0.6 / 0.5 |
|
||
| └ unattributed (dropping the previous revision) | ~7 |
|
||
| handler's own stages (`action{…}`) | 0.23 — `snapshot=hit` |
|
||
|
||
(This is the single run taken before anything changed. The same cell was
|
||
re-taken **paired and order-alternated** against the finished candidate
|
||
at the end of the round — 110.2 / 110.7 ms, flush wall 102.7 / 107.4 —
|
||
see "The paired result"; the stage shares agree, the absolute wire time
|
||
of this first run sat on a busier machine.)
|
||
|
||
Two of the review's candidates were answered by the split before
|
||
anything was built:
|
||
|
||
- **A second lint of the same revision: there is none.** `action` reads
|
||
`snapshot=hit` and `lint=0.00ms` on every try — the publish's pass is
|
||
the menu's pass, which is what review round §R1a bought.
|
||
- **A second analysis: there is none either.** `lint::context` already
|
||
lends `doc.semantics` to the linter (`with_semantics`), so the lint
|
||
pass does not re-`analyze` the tree.
|
||
|
||
So the cell is the rebuild, and the rebuild is **lex + parse** (54.7 ms
|
||
of the 100).
|
||
|
||
### 2026-09-12 — where the rebuild's milliseconds are
|
||
|
||
A standalone harness over exactly `Document::new`'s calls
|
||
(`scratchpad/63-2/micro`, 15 iterations, median; built against the
|
||
reference tree and against the working tree, same compiler, same file)
|
||
separates the clone from the parse, which the in-server stage cannot:
|
||
|
||
| | 0.53.0 (1b8723c) | after all three changes |
|
||
|---|---:|---:|
|
||
| `tokenize` | 27.79 | **11.59** |
|
||
| `tokens.clone()` | 4.44 | 3.92 |
|
||
| `parse_tolerant` | 17.47 | **16.33** |
|
||
| `collect_defines` | 0.45 | 0.42 |
|
||
| `analyze` | 9.79 | 9.40 |
|
||
| `LineIndex::new` | 0.56 | 0.59 |
|
||
| dropping the products | 6.27 | 6.40 |
|
||
| **total** | **66.8** | **48.6** |
|
||
|
||
193 816 tokens, `size_of::<Token>()` 120 bytes.
|
||
|
||
### 2026-09-12 — change 1: the lexer's two phases, fused
|
||
|
||
`crates/vlog_parser/src/lexer.rs` — `tokenize` lexed the whole file into
|
||
a `Vec<RawTok>` and then walked it to attach comments. Attachment reads
|
||
only the raw token in hand and the token last pushed, so the two loops
|
||
fuse into one without touching the result: `attach` / `attach_trailing`
|
||
are the same code as the second loop, called per raw token. The
|
||
intermediate vector for this file was 193 816 × 56 bytes of allocation,
|
||
growth copying and teardown. `tokens` is also given a capacity guess
|
||
(`estimated_tokens`, six bytes a token, capped at 2²⁰) — the growth
|
||
doubling reached 262 144 slots for this file anyway, so the guess costs
|
||
no memory it was not already taking.
|
||
|
||
The `blank_before` `if` whose two arms were the same expression is now
|
||
one expression, and `tokens.last_mut().unwrap()` is a `let … else`
|
||
(library paths take no `unwrap`).
|
||
|
||
**Measured** (same harness): `tokenize` 27.8 → **24.7 ms**.
|
||
|
||
*File size, for the lead:* `lexer.rs` is one of the two files the
|
||
2026-09-07 measurement left over 600 production lines (763). This round
|
||
leaves it at **770** — the fusion replaced the second loop with
|
||
`attach` / `attach_trailing` rather than adding a responsibility, and the
|
||
+7 is the doc comments on them. Splitting the lexer's two halves into
|
||
two modules would undo exactly the "one sentence" the fusion restored
|
||
(*it turns source text into the token stream, comments attached*), so the
|
||
lines were left where they are; the ruling is the lead's.
|
||
|
||
### 2026-09-12 — change 2: `Parser::skip`
|
||
|
||
`crates/vlog_parser/src/parser/cursor.rs` — `bump()` clones the token
|
||
(its `text` is a `String`, so an allocation) and hands it back; **217 of
|
||
its ~296 call sites threw the value away on the same line**. `skip()` is
|
||
`bump()` for those callers: same comment plumbing (the leading bucket and
|
||
the trailing comment are cloned into the pending lists, exactly as
|
||
`bump()` moved them out of its own copy), same cursor step, same
|
||
`self.tokens` left untouched — so a speculative parse's rewind finds the
|
||
stream exactly as it would have. The 217 sites were rewritten
|
||
mechanically; `eat_sym` / `eat_kw` are two of them.
|
||
|
||
**Measured**: `parse_tolerant` 17.5 → **16.0 ms**. (Modest: the 181
|
||
`expect_sym`/`expect_kw` calls whose token is also discarded still clone.
|
||
Left alone deliberately — a second pair of entry points for ~1 ms is not
|
||
worth the API.)
|
||
|
||
### 2026-09-12 — change 3: the operator table's first-byte test
|
||
|
||
`crates/vlog_parser/src/lexer.rs` — every token that was not a comment,
|
||
directive, attribute, string, escaped/system identifier, number or
|
||
identifier fell into `for op in OPERATORS { if self.starts_with(op) … }`:
|
||
**44 slice comparisons for every `;`, `(`, `)`, `,`, `.`, `[`, `]`** in
|
||
the file, which in a generated register file is most of the tokens. One
|
||
byte compare in front of the slice compare rejects every operator that
|
||
cannot start here. Longest-first order is untouched, `starts_with` still
|
||
decides, so the token stream cannot move.
|
||
|
||
**Measured**: `tokenize` 24.7 → **11.6 ms** — the single largest win of
|
||
the round, and a third of the whole cell.
|
||
|
||
### 2026-09-12 — one flaky test of my own, found and fixed
|
||
|
||
`lint_trace::tests::a_trace_holding_only_a_rebuild_is_not_empty` failed
|
||
once in six runs of `cargo test -p lucisv_server`: it armed a trace, ran
|
||
an **empty** closure under `rebuild(Rebuild::Analyze, …)` and asserted
|
||
the trace was not empty — but a closure that does nothing can measure
|
||
0.00 ms, which leaves the group equal to `Rebuilt::default()`. The
|
||
assertion was wrong, not the code: what says a rebuild happened is
|
||
`saw_document()`, which `Document::new` always calls, not a duration.
|
||
The test now calls it, and the reason is written above the test (this is
|
||
also why no test here asserts a millisecond — timing lives in the
|
||
harness). Six further runs of the module and two full workspace runs
|
||
green. The change is inside `#[cfg(test)]`, so the release binary the
|
||
paired numbers were taken with is the shipped code unchanged.
|
||
|
||
### Not taken, and why
|
||
|
||
- **The token-stream clone into `parse_tolerant`** (3.9 ms). The parser
|
||
*mutates* its token vector — `take_meta`, `take_dangling`, `take_gap`,
|
||
`take_leading_here`, `take_trailing_here` move comments out of it — so
|
||
a vector handed over and taken back is a comment-stripped vector, and
|
||
`Document::tokens` is read for comments by semantic tokens
|
||
(`tokens.rs:181`) and by the linter (`vlog_linter/src/context.rs:534`).
|
||
Handing it over would drop comments from highlighting and from the
|
||
rules that read them. Making the parser stop mutating the stream is a
|
||
real refactor of the comment plumbing for 3.9 ms; filed, not done.
|
||
- **`analyze` (9.4 ms) and `resolve_external` (5.5 ms)**: not opened.
|
||
The file ownership allows `vlog_semantic` "only for a measured stage",
|
||
and after the three changes above the gate is met with margin; a
|
||
fourth change would have bought risk, not a verdict.
|
||
- **Dropping the previous revision's products (6.3 ms)** happens inside
|
||
`set_document` on the request path. Moving it off the path means a
|
||
thread or a deferred queue in a single-threaded server; not for this
|
||
round.
|
||
|
||
## The paired result
|
||
|
||
Two binaries: the reference is `cargo build --release` of **1b8723c**
|
||
(0.53.0 plus §63.1) in a `git archive` scratch tree, the candidate is the
|
||
working tree. Same compiler, same harness, same opentitan at
|
||
`0098135…` with its three pre-existing modified files. Each phase run
|
||
**four times — ref, candidate, candidate, ref** — so an order effect or
|
||
a machine drift shows as a spread between a version's own two rounds.
|
||
One warm index store per binary. Three tries a row, median of the tries,
|
||
both rounds quoted. Evidence: `~/.cache/lucisv-perf/63-2/paired.jsonl`
|
||
(`paired.sh` is the runner), load 4.8 → 4.1 across the run.
|
||
|
||
| phase · row | 0.53.0 (a / b) | candidate (a / b) | verdict |
|
||
|---|---:|---:|---|
|
||
| **`offeredit` pinmux-comment, first offer after didChange** | **110.95 / 107.54** | **88.31 / 88.36** | **−19.2 %** — gate met, stretch (< 95) met |
|
||
| `offeredit` pinmux-comment, repeated offer, unchanged buffer | 0.27 / 0.32 | 0.22 / 0.19 | unchanged (noise) |
|
||
| `offeredit` aes-reg-instance, first offer after didChange | 5.23 / 8.10 | 6.54 / 6.24 | unchanged (inside the version's own spread) |
|
||
| `offeredit` aes-reg-instance, repeated offer | 3.39 / 4.22 | 3.48 / 3.18 | unchanged |
|
||
| `offeredit` tb-comment, first offer after didChange | 1.18 / 1.57 | 2.05 / 0.89 | unchanged |
|
||
| `offeredit` tb-comment, repeated offer | 0.22 / 0.28 | 0.32 / 0.23 | unchanged |
|
||
| `flush` didChange flush (foldingRange barrier) | 1.33 / 1.51 | 0.85 / 1.38 | unchanged |
|
||
| `diagnostics` publish after didChange (≈150 ms debounce) | 162.16 / 157.20 | 160.88 / 159.66 | unchanged |
|
||
| `offerkinds` — all 35 rows (5 cursors × 7 families) | 0.03 – 6.00 | 0.04 – 4.95 | every row inside its own version's a/b spread; the two rows above 1 ms (`aes-reg-instance` all-family 3.42/6.00 → 4.95/4.57 and `…ports` 2.99/3.73 → 2.92/2.83) do not move |
|
||
|
||
**Memory** (`rss`, three fresh processes a cell, KiB):
|
||
|
||
| cell | 0.53.0 | candidate |
|
||
|---|---:|---:|
|
||
| RSS after the workspace scan, cold cache | 505 968 / 508 048 / 505 824 · 501 200 / 501 232 / 505 312 | **478 992 / 479 584 / 480 720 · 480 848 / 479 344 / 479 488** |
|
||
| RSS after the workspace scan, warm cache | 428 480 / 429 104 / 425 312 · 427 392 / 430 720 / 427 968 | 427 872 / 428 160 / 426 928 · 427 056 / 427 888 / 427 632 |
|
||
| index store on disk | 45 468 | 45 468 |
|
||
|
||
Peak RSS is **not up**: warm is flat, and the cold scan — 3 975 files
|
||
lexed and parsed — is **~25 MiB lower**, which is the `Vec<RawTok>` the
|
||
fused lexer no longer builds.
|
||
|
||
**The flush split, paired** (`actionprofile`, pinmux-comment, first
|
||
codeAction after a didChange; the same four-run order; the trace is the
|
||
last try's, evidence `split-paired.jsonl`):
|
||
|
||
| | 0.53.0 + trace (a / b) | candidate (a / b) |
|
||
|---|---:|---:|
|
||
| wire latency, median of 3 | 110.2 / 110.7 | **89.1 / 89.1** |
|
||
| flush wall | 102.7 / 107.4 | **82.2 / 87.5** |
|
||
| ├ `lex` | 29.3 / 29.9 | **11.6 / 14.1** |
|
||
| ├ `parse` (clone inside) | 25.8 / 30.3 | 23.3 / 26.3 |
|
||
| ├ `publish` (of which `lint`) | 23.6 (23.4) / 23.2 (23.0) | 23.9 (23.7) / 23.3 (23.1) |
|
||
| ├ `analyze` | 10.7 / 11.3 | 10.4 / 10.7 |
|
||
| ├ `external` | 4.8 / 4.7 | 4.7 / 4.7 |
|
||
| └ `lines` / `defines` | 0.6 / 0.4 | 0.7 / 0.4 |
|
||
| handler (`action`) | `snapshot=hit` | `snapshot=hit` |
|
||
|
||
## Parity
|
||
|
||
Nothing below is an assertion about intent; each is a comparison of two
|
||
builds' outputs over real files.
|
||
|
||
1. **The token stream, the parse diagnostics, the whole AST and the
|
||
symbol table, file by file.** A digest per file over every token's
|
||
kind, text, line, column, span start/end, `blank_before` and every
|
||
leading/trailing comment, then over `{:?}` of the diagnostics, of the
|
||
`SourceFile` and of `analyze`'s symbols. Run with the same tool built
|
||
against the reference tree and against the working tree, over
|
||
**4 807 files** (860 corpus + 3 947 opentitan): **0 lines differ**
|
||
(`digest-ref.txt` / `digest-new.txt`, `digest.diff` empty).
|
||
2. **`format --stdout`, corpus.** 860 files, sha256 per file, reference
|
||
binary vs candidate: **0 differ** (`fmt-ref.txt` / `fmt-new.txt`).
|
||
3. **`format --stdout`, opentitan.** The whole tree in one run, both
|
||
binaries: the same sha256 over the concatenated output
|
||
(`2c363ec2eb8395…`) and byte-identical stderr.
|
||
4. **Diagnostics and the menu, on the buffer this round is about.**
|
||
`parity_menu.py` opens each of the three cursors' files, asks for the
|
||
all-family menu and each of the seven `context.only` families —
|
||
recording every action's **title, kind and edit payload** — collects
|
||
the published diagnostics, then does it twice more after a
|
||
`didChange`: once with a harmless comment appended and once with a
|
||
revision that deliberately introduces lint findings (a tab, a 140-
|
||
character line, a trailing space), so the comparison is not two empty
|
||
lists. 87 lines including 12 diagnostics and the fix-all edits:
|
||
**identical** (`parity-ref.txt` / `parity-new.txt`).
|
||
5. **Suites.** `cargo test --workspace --locked` through the guard:
|
||
reference **4 403 passed, 0 failed, 46 ignored**; candidate **4 406
|
||
passed, 0 failed, 46 ignored** — +3, the new `lint_trace` tests. The
|
||
parser snapshot and idempotency suites are inside that run
|
||
(`vlog_parser` 380 + 22 span tests, `vlog_formatter` 226 + fixtures),
|
||
green on their own too. `cargo fmt --all -- --check` and
|
||
`cargo clippy --all-targets --locked` clean. No guard kill anywhere in
|
||
the round.
|
||
6. **opentitan untouched.** `git -C ~/repo/opentitan status --porcelain`
|
||
before and after every phase lists exactly the three pre-existing
|
||
modified files (`hw/ip/aes/dv/tb/tb.sv`,
|
||
`hw/top_darjeeling/ip/ast/rtl/ast.sv`,
|
||
`hw/top_earlgrey/ip/ast/rtl/ast.sv`) and nothing else.
|
||
|
||
### Re-deriving it
|
||
|
||
Everything is under `~/.cache/lucisv-perf/63-2/`: both server binaries
|
||
(`server-ref-0.53.0`, `server-step1-trace` — the reference plus the
|
||
instrumentation only —, `server-step2-lexparse`), both CLIs
|
||
(`lucisv-ref`, `lucisv-new`), the reference tree (`ref-1b8723c/`), the
|
||
runners (`run.sh`, `paired.sh`, `split.sh`, `fmtgate.sh`,
|
||
`parity_menu.py`), the file lists and every `.jsonl` / `.txt` named
|
||
above, plus the stage micro-harness's sources — `micro/` (path
|
||
dependencies on the working tree) and `micro-ref/` (on `ref-1b8723c/`).
|
||
Both are plain `cargo` crates with no third-party code; `micro`'s
|
||
`main.rs` is the per-stage median table and its `bin/digest.rs` is the
|
||
per-file digest of parity check 1.
|
||
|
||
## For `docs/perf/README.md` (the lead's file)
|
||
|
||
> **2026-09-12 — the first request after an edit (TODO §63.2, N1 of the
|
||
> 0.52.0 review).** The 40 267-line pinmux cell — one-character
|
||
> `didChange`, then the all-family `codeAction` menu — **109 → 88 ms
|
||
> paired (−19.2 %)**, the unchanged-repeat cell and every other
|
||
> `offeredit`/`offerkinds`/`flush`/`diagnostics` row within noise, cold
|
||
> scan RSS ~25 MiB lower and warm RSS flat. The flush is now split in
|
||
> the `timing: codeaction` line (`rebuild{lex parse defines analyze
|
||
> external lines publish documents}`), which is what named the cost:
|
||
> **lex 29 ms and parse 26 ms of a 100 ms flush**, and *no* second lint
|
||
> and *no* second analysis of the revision (the snapshot and
|
||
> `with_semantics` already had those). Three changes, all in
|
||
> `vlog_parser`: the lexer's two phases fused (the intermediate
|
||
> `Vec<RawTok>` is gone; 27.8 → 24.7 ms), `Parser::skip` for the 217
|
||
> `bump()` sites that discarded the token (17.5 → 16.0 ms), and a
|
||
> first-byte test in front of the 44-entry operator table (24.7 →
|
||
> **11.6 ms** — the single largest win). Token stream, parse
|
||
> diagnostics, AST and symbol table digested per file over 4 807 files:
|
||
> 0 differ; `format --stdout` byte-identical over corpus and opentitan;
|
||
> diagnostics and menus identical on the edited buffer.
|
||
> **Filed, not fixed:** the token clone into `parse_tolerant` (3.9 ms —
|
||
> the parser mutates the stream it is given, so it cannot be handed
|
||
> over while `Document::tokens` is read for comments), `analyze`
|
||
> (9.4 ms), `resolve_external` (4.7 ms), and the ~6 ms spent dropping
|
||
> the previous revision's products on the request path.
|
||
|
||
## QA log
|
||
|
||
### 2026-09-12 — TODO §63.2 verified: PASS
|
||
|
||
Verified the flush split, the three lexer/parser changes, and the lead's
|
||
`attach_trailing` edit. Everything below was re-derived independently
|
||
(own tools, own binaries, own re-run of the dev's evidence), not read off
|
||
the dev's numbers. Scratch work: `/private/tmp/.../scratchpad/63-2-qa/`
|
||
(a fresh clone of 1b8723c at `old_lucisv/`, a paired-QA benchmark run at
|
||
`paired-qa/`).
|
||
|
||
**Gates** (all through `tools/guard.sh -m 8 -t 1800`, no guard kill
|
||
anywhere):
|
||
- `cargo test --workspace`: **4 422 passed, 0 failed** (run alone, no
|
||
concurrent cargo invocation — an earlier attempt run *concurrently*
|
||
with another `cargo test`/`cargo build` in the same tree hit a stale
|
||
doctest rlib once; that is a target-dir race from running two cargo
|
||
processes at once, not a code defect, and does not reproduce solo).
|
||
4 406 (the dev's count) + 16 tests this round added (13 in
|
||
`vlog_parser::lexer::tests`, 2 in `lucisv_server::state::tests`, 1 in
|
||
`lucisv_server::lint_trace::tests`) = 4 422.
|
||
- `cargo clippy --all-targets --workspace`: clean, 0 warnings.
|
||
- `cargo fmt --all -- --check`: clean.
|
||
|
||
**Fuzzers** (`docs/topo.md`'s `comment-slots` row names four; the SVA
|
||
fuzzer is `sva-bodies`'s): `cargo test -p vlog_formatter --test
|
||
verification a_comment_in_every_` — covergroup, fragment, constraint,
|
||
RTL, SVA, **5/5 pass, still at their pinned gap counts** (329/153/395/
|
||
419-class/705). No formatter or comment-slot code was touched by this
|
||
round, so this is a regression check, not new coverage — it stayed at
|
||
zero.
|
||
|
||
**`skip` vs `bump`, mechanically, not by reading the diff**: a script
|
||
diffed old and new `crates/vlog_parser/src/parser/*.rs` and asserted
|
||
every hunk is `bump()` → `skip()` and nothing else (line-for-line, same
|
||
whitespace). Result: **every one of 178 hunks matches that shape**, and
|
||
every removed line is a bare `self.bump();` statement (verified
|
||
separately — `grep '^-' | grep -v 'self\.bump();'` on the parser diff
|
||
returns nothing but the lexer's unrelated deleted lines and the two
|
||
`eat_sym`/`eat_kw` bodies, both bare-statement too). Cross-checked: 252
|
||
`Parser::bump()` call sites existed in `parser/` at 1b8723c, 74 remain
|
||
(all `.bump().text` or similar — value used, correctly untouched),
|
||
252 − 74 = 178, matching exactly.
|
||
|
||
- **Finding (non-blocking, doc-only): the "217 call sites" claim in the
|
||
Work log and TODO.md §63.2 does not match the diff.** The diff converts
|
||
**178** call sites (176 direct + the 2 inside `eat_sym`/`eat_kw`), not
|
||
217. `~296` (Work log) is real — it is the *textual* `.bump()` count
|
||
across all of `vlog_parser/src` including `RawLexer::bump` (a
|
||
different, unrelated function) — but 217 does not correspond to any
|
||
count I could reproduce from the tree at 1b8723c or from the diff. Not
|
||
a safety issue (every conversion that *did* happen is a verified-safe
|
||
shape, and no unused-result `self.bump();` statement remains anywhere
|
||
in `parser/`), but the number should read 178 wherever it is quoted
|
||
again (the Work log, TODO.md §63.2, and the `docs/perf/README.md` paste
|
||
in this file all repeat it). Left the dated Work log entries as the
|
||
historical record; not editing them.
|
||
- **Finding (fixed directly, typo-class): the operator table has 42
|
||
entries, not 44.** Counted `OPERATORS` in `lexer.rs` by hand and by
|
||
script: 42. The inline code comment said "44 spellings" — fixed to 42
|
||
(`crates/vlog_parser/src/lexer.rs`, the comment above the first-byte
|
||
test). The Work log prose and TODO.md still say 44; same disposition as
|
||
above — noted, not rewritten.
|
||
|
||
**Comment-attachment attacks on the fused lexer** (item 4): built
|
||
`tokenize` from 1b8723c in a fresh clone (`old_lucisv/`) and from the
|
||
working tree as two throwaway `examples/qa_token_digest.rs` /
|
||
`qa_dump_one.rs` binaries (removed after use — not part of this diff).
|
||
- **Whole corpus + opentitan, re-derived independently**: token stream +
|
||
parse-tree + diagnostics digest (a hash of `{:?}` output, not read from
|
||
the dev's cached digest files) over the same **4 807-file list** the
|
||
dev used (`~/.cache/lucisv-perf/63-2/files-all.txt`): **0 lines
|
||
differ**.
|
||
- **The ten named attack shapes** (comment first in file; two comments
|
||
before any token; trailing comment at EOF; two block comments merging
|
||
on one line; a blank line between a comment and its token; CRLF; a
|
||
block comment spanning lines before a same-line token; a comment
|
||
between a macro invocation and its arguments; a file that is only
|
||
comments; an empty file): dumped full `Debug` token streams for all
|
||
ten from both builds — byte-identical hashes and, for the trickier
|
||
three (merge, macro-comment, multi-line block), eyeballed the raw
|
||
`Debug` output for sanity. Pinned as **ten new tests** in
|
||
`crates/vlog_parser/src/lexer.rs`'s `mod tests` (search
|
||
`TODO §63.2 QA`), all passing.
|
||
- The lead's `attach_trailing` edit (returns the comment instead of
|
||
dropping it when there is no previous token): confirmed the branch is
|
||
unreachable through `tokenize` today (`attach` only calls
|
||
`attach_trailing` when `same_line_as_prev` is true, which already
|
||
requires `!tokens.is_empty()`), so it changes nothing observable yet
|
||
and is a correct hardening of invariant 3 for whichever future caller
|
||
removes that guard. Compiles clean, no test regressed.
|
||
|
||
**Operator table** (item 5): three new tests in `lexer.rs`.
|
||
- `every_operator_s_first_byte_is_a_single_ascii_byte` — all 42 entries.
|
||
- `the_operator_table_has_no_duplicate_or_empty_entries`.
|
||
- `every_operator_followed_by_every_other_operator_still_lexes_without_a_gap`
|
||
— all 42×42 = 1 764 concatenations, asserted to round-trip with no gap.
|
||
Cross-checked the same 1 764 pairs against 1b8723c with the throwaway
|
||
digest tool: **0 differ**.
|
||
|
||
**Idempotency and snapshots** (item 6): `cargo test -p vlog_formatter`
|
||
green as part of the full workspace run above (`fixtures_match_snapshots
|
||
_and_are_idempotent` passes). `tools/corpus_check.sh corpus -b
|
||
target/release/lucisv`: 814/820 parse & format, 0 verification errors, 0
|
||
crashes, and the outcome column is **byte-for-byte identical to the
|
||
tracked `corpus-check-results.tsv`** for all 820 files. `format --stdout`
|
||
byte-identity: **corpus, 0 differ** (stdout and stderr both, against
|
||
`~/.cache/lucisv-baselines/lucisv-0.53.0`); **opentitan `hw/ip`
|
||
(1 807 files), 0 differ**, same 4 parse errors both binaries, run through
|
||
the guard. `git -C ~/repo/opentitan status --porcelain` before and after:
|
||
only the three pre-existing files, every time.
|
||
|
||
**sha256 / rebuild check** (item 7 precondition): a fresh
|
||
`cargo build --release` of the working tree's `lucisv` CLI matches
|
||
`~/.cache/lucisv-perf/63-2/lucisv-new` byte for byte
|
||
(`fabd3432…bdfcfaf`) — the lead's edit landed before that binary was
|
||
built. **`lucisv-server` does *not* match**: `server-step2-lexparse`
|
||
(built 01:23) is `b0b09544…`, a fresh build of the current tree is
|
||
`694287ea…`. The lead's edit landed between the two builds (01:23 →
|
||
01:25), so the server binary used for the dev's own paired run predates
|
||
it. Per the brief, rebuilt the candidate and re-ran the paired benchmark
|
||
against the fresh binary rather than trusting the cached one.
|
||
|
||
**Paired re-take** (item 7), `paired-qa.sh` (same shape as the dev's
|
||
`paired.sh`, ref/new alternated, 3 tries, one warm store per binary),
|
||
against the freshly built candidate `lucisv-server` (694287ea…) and the
|
||
reference rebuilt from 1b8723c and hash-verified against
|
||
`server-ref-0.53.0` (6b1b5245…, matches):
|
||
|
||
| cell | ref (a/b) | candidate (a/b) | change |
|
||
|---|---:|---:|---|
|
||
| `offeredit` pinmux-comment, first after didChange (median of 3) | 112.31 / 110.63 | 90.35 / 92.57 | **−19.6% / −16.3%**, gate (≥15%) met both rounds, stretch (<95ms) met |
|
||
| `offeredit` aes-reg-instance, first after didChange | 6.32–7.82 | 2.94–8.05 | inside noise, matches dev's characterization |
|
||
| `offeredit` tb-comment, first after didChange | 0.56–3.94 | 0.56–3.08 | inside noise |
|
||
| `offerkinds`, 35 rows | 0.03–6.0 ms | 0.03–5.0 ms | no row moved out of range |
|
||
| RSS cold | 502.7–505.2 MiB | 478.6–483.1 MiB | lower, matches "cold ~25 MiB lower" |
|
||
| RSS warm | 427.4–429.4 MiB | 426.9–429.3 MiB | flat |
|
||
|
||
This run was **not** on an idle machine (a `cargo test --workspace` was
|
||
running concurrently in the background for part of it), which is why the
|
||
absolute ms are a little higher than the dev's own quieter-machine
|
||
numbers — the percentage reduction and every qualitative claim
|
||
(noise-level `offerkinds`/other cursors, RSS direction) hold anyway, so
|
||
the gate is met with margin either way.
|
||
|
||
Also re-ran `parity_menu.py` (item covering TODO.md's "an edit that
|
||
moves a fence" attack, plus the lex-failure and `define`-table attacks
|
||
below) against the freshly built ref/candidate pair: **87 lines, 0
|
||
differ**, same as the dev's own run — the LINTY edit's fence/lint-finding
|
||
path is unaffected.
|
||
|
||
**TODO.md's three named parity attacks** — a buffer that fails to lex, a
|
||
`` `define `` edit that changes the macro table, an edit that moves a
|
||
fence:
|
||
1. **Lex failure**: new test
|
||
`a_buffer_that_fails_to_lex_still_records_every_rebuild_stage`
|
||
(`state/mod.rs`) — an unterminated string literal, confirms `tokens`
|
||
stays empty, a diagnostic is produced, `Rebuild::Lex` is still
|
||
recorded (the failed attempt is real work), and every other stage
|
||
(`defines`/`analyze`/`external`/`lines`/`publish`) still runs over the
|
||
empty tree exactly as the un-instrumented code always did.
|
||
2. **`define` edit**: new test
|
||
`a_define_edit_changes_the_macro_table_the_rebuild_reports_on` —
|
||
two `Document::new` calls with different macros, confirms the second
|
||
document's table has no trace of the first's macro (no cross-document
|
||
staleness introduced by wrapping `collect_defines` in `rebuild`).
|
||
3. **Fence-moving edit**: covered by the `parity_menu.py` re-run above
|
||
(the LINTY revision is exactly this — a new lint finding changes what
|
||
the fence/diagnostics path reports for the revision).
|
||
|
||
**`lint_trace` arithmetic — sabotaged, as asked** (item 8): nested
|
||
`rebuild{…}` inside `flush{…}` in `Trace::line()` and reran the dev's
|
||
pinning test, `the_rebuild_group_names_every_stage_beside_the_other_two`.
|
||
**It did not fail.** That test extracts the rebuild body by splitting on
|
||
the literal string `"rebuild{"` and the *next* `}`, which finds a clean
|
||
body whether or not another `}` follows — the extra brace the nesting
|
||
adds sits outside the slice the test inspects. Checked what actually
|
||
happens to a consumer against `tools/perf/phases_p2.py`'s real regex
|
||
(`([a-z_]+)\{([^{}]*)\}`, which cannot cross an inner `{`): run against
|
||
the sabotaged line, `GROUP.findall` matched only `rebuild` and `action`
|
||
— **the whole `flush` group silently fails to match**, and
|
||
`flush_wall`/`flush_buffers`/`flush_parses` and every `flush.fields()`
|
||
key vanish from that row with no error anywhere. So the existing pin
|
||
does not actually enforce the sibling-group contract it documents.
|
||
Added `the_three_top_level_groups_are_flat_never_nested` to
|
||
`lint_trace.rs`'s test module, which reads the line the way the regex
|
||
does (each group must reach its own `}` before another `{` opens) —
|
||
confirmed it **fails** against the sabotaged code and **passes** after
|
||
reverting the sabotage; the sabotage itself is reverted (`git diff` of
|
||
`lint_trace.rs` no longer shows it). This is the one finding I'd call a
|
||
real gap rather than a documentation slip, though it is a `tools/perf`
|
||
tooling-correctness issue, not a formatter-invariant one (no corpus/
|
||
opentitan output is affected), so it does not block this round; filed as
|
||
a fix-directly-and-note per CLAUDE.md's QA rule since the fix is a test
|
||
addition, not a redesign.
|
||
|
||
**Not independently re-verified**: the dev's own `flush`/`diagnostics`
|
||
paired cells (only `offeredit`/`offerkinds`/`rss` were named in my brief
|
||
for item 7); the micro-harness per-stage table (`tokenize` 27.79→11.59ms
|
||
etc.) — trusted as reported, since the stage split itself is exercised
|
||
by the corpus-wide digest and the paired re-take above.
|
||
|
||
**Verdict: PASS.** No corpus, opentitan, snapshot, idempotency or
|
||
comment-preservation regression found anywhere; the two real findings
|
||
are a documentation/count inaccuracy (217→178, 44→42, the latter fixed)
|
||
and a test-strength gap in the sibling-group pin (fixed with a new test
|
||
that actually catches the nesting failure mode). Gate met with an
|
||
independently-measured margin on a busier machine than the dev's own
|
||
run.
|
||
|
||
## Review
|
||
|
||
**Lead review, 2026-09-12 — accepted.** The lane did what the brief
|
||
asked in the order it asked: the flush split came first and it settled
|
||
two of the review's candidates without code (no second lint, no second
|
||
analysis), then named the two stages that mattered — lex and parse, 55 of
|
||
a 100 ms flush. The three changes are all in `vlog_parser` and all
|
||
behaviour-preserving by construction: the lexer fusion is a reordering of
|
||
the same attachment loop (the fused `attach` reads only the raw token in
|
||
hand and the token last pushed, which is all the old loop ever read),
|
||
`Parser::skip` is `bump` minus the clone with the same comment plumbing,
|
||
and the first-byte test in front of the operator table is a filter in
|
||
front of an unchanged `starts_with`. The proof is the one that matters for
|
||
a lexer change: token stream, diagnostics, AST and symbols digested per
|
||
file over 4 807 files with 0 differing, re-derived by QA from a rebuilt
|
||
1b8723c, plus the five gap fuzzers at their pinned counts and every
|
||
byte-identity gate. Gate met at −19.2 % (dev) and −19.6 % / −16.3 % (QA's
|
||
re-take on a busier machine), stretch met.
|
||
|
||
One edit is the lead's, and QA covered it: `attach_trailing` now hands an
|
||
orphan comment back to `pending` instead of returning silently — the
|
||
branch is unreachable while `same_line_as_prev` requires a token, and it
|
||
stays a rule rather than a hope (invariant 3).
|
||
|
||
Rulings on QA's findings:
|
||
|
||
- **Counts** (217 call sites and 44 operators in the Work log; 178 and
|
||
42 in the tree): the Work log stands as a dated record; the lead's own
|
||
entry in `docs/perf/README.md`, TODO §63.2 and the topo row carry the
|
||
verified numbers.
|
||
- **The nesting guard**: the dev's pin string-split the line and missed a
|
||
nested group; QA's `the_three_top_level_groups_are_flat_never_nested`
|
||
runs the real regex and catches the sabotage. Accepted as the pin.
|
||
|
||
Deferred with the dev's reasons and filed in TODO's loop-3 list: the
|
||
token clone into `parse_tolerant` (the parser mutates the stream it is
|
||
given), `analyze`, `resolve_external`, and dropping the previous revision
|
||
on the request path. `lexer.rs` at 770 production lines is noted: the
|
||
fusion removed a responsibility rather than adding one.
|
||
|
||
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->
|