The didOpen delay: undriven-net asks the workspace census last, not once per declaration
TODO §46 (docs/features/didopen-cost). Closes take-3 finding §8.4 (§44b). Measured first: on opentitan the open of a 42 192-line file cost 1 745 ms, of which the lint pass was 1 654 ms and `undriven-net` alone 1 608 ms — the rule asked `WorkspaceIndex::files_mentioning` (a walk over all 3 976 indexed files) once per declaration, ahead of the local guards that silence almost all of them. Six lines reordered so the oracle is asked last, as `unused-signal` always did: same findings, same order (pinned by a counting-oracle unit test that fails on a revert, and shown byte-identical against 0.43.0 over a crafted workspace and four opentitan IPs). didOpen → next request: 1 742 → 117 ms on the largest file, 51–95 → 5–8 ms on typical IPs, the same on every keystroke flush. No debounce added; three wire-level pins with a debug-build bound. Docs: take-3 §8.4 annotated, docs/perf/README.md entry. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
f7956060b3
commit
8145a67be6
6 files changed
+972
-18
No files matched your search
@@ -4563,12 +4563,20 @@ since 0.39.0. Two findings are real work and wait for the owner's call:
|
||||
the server needs building per tag) and fix the regression, or rule
|
||||
that non-resolving clients are not a hot path (VS Code, Neovim's
|
||||
built-in client and Helix all resolve).
|
||||
- [ ] **A `didOpen` of a file already in scope delays the next request by
|
||||
- [x] **A `didOpen` of a file already in scope delays the next request by
|
||||
21–51 ms**, scaling with file size (take 2: 2–4 ms). The open, not
|
||||
the request. Find what the open now does synchronously that it did
|
||||
not (the §33+ diagnostics pass? the §37 lint run construction?) and
|
||||
move it off the request path or measure it as the price of the
|
||||
diagnostics the file gets.
|
||||
diagnostics the file gets. — done by §46 (0.44.0), and it was
|
||||
neither: the lint pass is 75–95 % of the open and the rule
|
||||
`undriven-net` is 90–97 % of the lint pass, because it asked the
|
||||
workspace census once per declaration in the buffer before its own
|
||||
local guards could silence it. Asked last now, as its twin rule
|
||||
`unused-signal` always has. 51/70/95 → 4.6/7.3/7.8 ms on the three
|
||||
files of take 3 §8.4; 1 742 → 117 ms on opentitan's 42 192-line
|
||||
`pinmux_reg_top.sv`. Not a regression — 0.39.0 measures the same.
|
||||
`docs/features/didopen-cost/README.md`.
|
||||
- Noted, not actioned: `lucisv check` 6–10 % slower than 0.39.0 on
|
||||
`hw/ip` (73 rules vs 54; per-rule cost flat), `workspace/symbol`
|
||||
drifting 6.6 → 7.9 ms over three takes, `rename` 115 → 152 ms with two
|
||||
@@ -4704,9 +4712,86 @@ request waits for.
|
||||
open of an edited-on-disk file sees the buffer's text; the take-3 rows
|
||||
re-measured in the README.
|
||||
|
||||
- [ ] measurement + profile, in the README
|
||||
- [ ] the fix, with the ≤ 5 ms return contract pinned
|
||||
- [ ] docs; §44b ticked; take-3 finding 2 annotated
|
||||
- [ ] Gates (guarded); the take-3 rows re-measured
|
||||
- [ ] QA: the driver re-run on the three files at three sizes; the
|
||||
diagnostics still arrive; no request answered from stale state
|
||||
- [x] measurement + profile, in the README — and the finding understated it:
|
||||
`pinmux_reg_top.sv` (42 192 lines) delayed the next request by **1 742
|
||||
ms**, of which 1 608 was the one rule `undriven-net` asking the
|
||||
workspace census once per declaration ahead of its own local guards
|
||||
- [x] the fix, with the ≤ 5 ms return contract pinned — the census question
|
||||
moved behind the guards, where `unused-signal` has always asked. Met
|
||||
for a generated 1 000-line buffer (<2 ms); 5.9–6.9 ms for
|
||||
`aes_core.sv`, 1 145 lines of dense RTL whose 3.0–4.4 ms of parse
|
||||
cannot be deferred without answering the next request from stale
|
||||
state. Recorded as the limit in the README, not redefined
|
||||
- [x] docs; §44b ticked; take-3 finding 2 annotated — the annotation text and
|
||||
a `docs/perf/README.md` entry are in the feature README under "Docs to
|
||||
apply at merge (lead)"
|
||||
- [x] Gates (guarded); the take-3 rows re-measured — 3 814 tests (was 3 810),
|
||||
corpus 814/820 same six, clippy and fmt clean, smoke OK; §8.4's three
|
||||
files 51/70/95 ms → 4.6/7.3/7.8 ms
|
||||
- [x] QA: the driver re-run on the three files at three sizes; the
|
||||
diagnostics still arrive; no request answered from stale state —
|
||||
PASS, independently re-derived on a new driver: 0.43.0 vs fixed
|
||||
3.4×/11×/17× on aes.sv/aes_core.sv/pinmux_reg_top.sv; opentitan
|
||||
`hw/ip/{aes,hmac,spi_device}` and
|
||||
`hw/top_darjeeling/ip_autogen/pinmux` byte-identical; counting-oracle
|
||||
test confirmed to fail on a hand-reverted scratch copy; gates
|
||||
reproduced (3814/0/44, corpus 814/820, clippy/smoke clean); QA log
|
||||
in `docs/features/didopen-cost/README.md`
|
||||
|
||||
## 47. Type-name spans on the AST; retire `vlog_semantic/src/scan.rs` (planned 2026-09-05) — topo §2.9-2
|
||||
|
||||
One lane after 0.44.0, §36's protocol. Feature README:
|
||||
`docs/features/type-name-spans/README.md`. Ships in 0.45.0 with §48/§49.
|
||||
|
||||
`vlog_semantic/src/scan.rs` (193 lines) recovers the byte range of a name
|
||||
the AST kept only as a `String` by scanning the construct's source text.
|
||||
Its two remaining users, both in `bind/`: `bind/decl.rs` (the type name of
|
||||
a declaration — `DataType::name`, split as `pkg::item` into unit and item
|
||||
spans by `NameScanner`, or as `iface.modport` into head and tail) and
|
||||
`bind/stmt.rs` (`disable <label>`). Every other name already has
|
||||
`name_span` on its node (`src[name_span] == name` is pinned over the corpus
|
||||
census, 21 485 symbols).
|
||||
|
||||
- **`DataType::name_span: TextRange`** — the range of the name exactly as
|
||||
written, so `src[name_span]` is `pkg::item` (with an escaped segment's
|
||||
trailing space, §29) or `iface.mp`. Set by every site that builds a
|
||||
`DataType` (`parse_type_ref`, the implicit/`logic` cases — for an
|
||||
implicit type with no written name, the empty range at the position the
|
||||
name would have had, the convention `name_span` already uses for the
|
||||
unnamed-DPI-formal case, decl.rs:436). Segment spans are derived from
|
||||
`name_span` alone — split the *span's own text* on `::`/`.`, never
|
||||
rescan the construct — in one helper `DataType::segments() ->
|
||||
impl Iterator<Item = (&str, TextRange)>`.
|
||||
- **Size.** `DataType` rides in every `Expr` through `ExprKind::Type`;
|
||||
`size_pins` holds `Expr ≤ 96`. Measure before and after; if the 8 bytes
|
||||
push `Expr` over, move `name_span` into the already-boxed `TypeExtra`
|
||||
(making `extra` `Some` whenever a name is written) or box — say which
|
||||
and why; the pin does not move.
|
||||
- **`StmtKind::Disable`** (and any other statement that names a label or
|
||||
identifier as a bare `String` — grep `scan::` and `String` names in
|
||||
`ast/stmt.rs`) gains `name_span` the same way.
|
||||
- **Delete `scan.rs`**, its `mod`, and the `src` parameter the README's
|
||||
Handshakes say goes with it if nothing else reads it; the binder reads
|
||||
the spans. `vlog_semantic/README.md` and `docs/features/vlog-semantic/README.md`
|
||||
Handshakes updated (delivered).
|
||||
- **Consumers that benefit:** hover/definition/references on a type name
|
||||
(`nav.rs`, `hover.rs`) — nothing to change if they already go through
|
||||
`Reference::name_span`; confirm, and add a test that definition on
|
||||
`pkg::t` in a declaration lands on `t`'s declaration with the *item*
|
||||
range selected, and on `bus_if.mp` on the interface with the head range.
|
||||
- Pins: the corpus census assertion `src[name_span] == name` now covers
|
||||
type-name references too (extend `tests/census.rs` or the semantic
|
||||
corpus test that holds the 21 485 number — report the new count);
|
||||
strict/tolerant parity; byte-identity of every corpus file (the
|
||||
formatter does not print spans); `cargo test --workspace`; opentitan
|
||||
sweep unchanged; a before/after of `definition` on 200 type-name
|
||||
positions over opentitan (read-only) to show nothing regressed.
|
||||
|
||||
- [ ] 47.1 `DataType::name_span` + `segments()`, size ruled
|
||||
- [ ] 47.2 `StmtKind::Disable` name span
|
||||
- [ ] 47.3 `scan.rs` deleted; binder reads spans; census pin extended
|
||||
- [ ] docs: feature README; topo §2.9-2 struck (lead); semantic READMEs
|
||||
- [ ] Gates (guarded)
|
||||
- [ ] QA: census re-derived; escaped and scoped type names; `iface.mp`
|
||||
ports; implicit types; definition/hover on type names over
|
||||
opentitan (read-only)
|
||||
@@ -7963,3 +7963,207 @@ fn the_cli_and_the_server_run_the_same_rules_for_the_same_buffer() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// TODO.md §46 — what a `didOpen` costs the request behind it
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// `talk` writes a whole session before reading a byte, which is what every
|
||||
// test above wants and what a *timing* test cannot use: the number this round
|
||||
// is about is the gap between the `didOpen` frame going out and the next
|
||||
// response coming back. `Live` — the held-open session two hundred lines up —
|
||||
// is the one that can measure it. The three tests below are §46's contract:
|
||||
// the open returns to the loop fast, the first request after it is answered
|
||||
// from the **buffer**, and the diagnostics still arrive with no edit and no
|
||||
// further request behind them.
|
||||
|
||||
/// A started session over `root`, indexed at the whole-workspace scope with
|
||||
/// the scan already run — the barrier request at the end is what makes that
|
||||
/// true, since the loop answers nothing until a rescan a message asked for has
|
||||
/// finished.
|
||||
fn live_at(root: &Path) -> Live {
|
||||
let mut live = Live::start();
|
||||
live.send(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":1,"method":"initialize","params":{{"processId":null,"rootUri":"file://{}","capabilities":{{}}}}}}"#,
|
||||
root.display()
|
||||
));
|
||||
live.wait_for(|m| m["id"] == 1);
|
||||
live.send(r#"{"jsonrpc":"2.0","method":"initialized","params":{}}"#);
|
||||
live.send(WIDE_SCOPE);
|
||||
live.send(r#"{"jsonrpc":"2.0","id":2,"method":"workspace/symbol","params":{"query":"zzz"}}"#);
|
||||
live.wait_for(|m| m["id"] == 2);
|
||||
live
|
||||
}
|
||||
|
||||
/// The `didOpen` frame for a buffer.
|
||||
fn open_frame(uri: &str, text: &str) -> String {
|
||||
format!(
|
||||
r#"{{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{{"textDocument":{{"uri":"{uri}","languageId":"systemverilog","version":1,"text":{}}}}}}}"#,
|
||||
serde_json::to_string(text).expect("json")
|
||||
)
|
||||
}
|
||||
|
||||
/// Open `uri` and ask for a `hover` in the same write, and report how long the
|
||||
/// hover took to come back.
|
||||
///
|
||||
/// That wait *is* the open: the loop is synchronous, so whatever the open does
|
||||
/// before returning to it is what the hover queues behind.
|
||||
fn open_then_hover(live: &mut Live, id: u32, uri: &str, text: &str) -> std::time::Duration {
|
||||
let hover = format!(
|
||||
r#"{{"jsonrpc":"2.0","id":{id},"method":"textDocument/hover","params":{{"textDocument":{{"uri":"{uri}"}},"position":{{"line":0,"character":8}}}}}}"#
|
||||
);
|
||||
let started = std::time::Instant::now();
|
||||
live.send(&open_frame(uri, text));
|
||||
live.send(&hover);
|
||||
live.wait_for(|m| m["id"] == id);
|
||||
started.elapsed()
|
||||
}
|
||||
|
||||
/// A workspace of `files` small packages, so the index holds a *project*
|
||||
/// rather than one buffer — which is what switches the cross-file lint rules
|
||||
/// on at all (`LintRun::for_document`).
|
||||
fn indexed_neighbours(dir: &Path, files: usize) {
|
||||
for k in 0..files {
|
||||
std::fs::write(
|
||||
dir.join(format!("pkg{k}.sv")),
|
||||
format!("package pkg{k};\n localparam int K{k} = {k};\nendpackage\n"),
|
||||
)
|
||||
.expect("write neighbour");
|
||||
}
|
||||
}
|
||||
|
||||
/// §46's contract, on the wire: a `didOpen` of a 2 000-line buffer must not
|
||||
/// leave the request behind it waiting.
|
||||
///
|
||||
/// **An upper bound, not a benchmark, and a debug-build one.** `cargo test`
|
||||
/// builds unoptimized, where one tolerant parse of 2 000 lines is ~53 ms all
|
||||
/// by itself — measured on this machine, and stable to a millisecond across
|
||||
/// runs. So the 200 ms here is that floor with room for a loaded CI box, not
|
||||
/// the ≤ 25 ms §46 asked for: **that figure is a release number**, and the
|
||||
/// release binary opens the same buffer in 2–4 ms.
|
||||
///
|
||||
/// **What this test does and does not catch.** It catches an open that starts
|
||||
/// doing something *unbounded* — the shape §46 fixed. It cannot catch the
|
||||
/// §46 defect itself at this size: the census walk that cost 1.6 s on
|
||||
/// opentitan's 42 000-line `pinmux_reg_top.sv` costs milliseconds over a
|
||||
/// forty-file fixture, and a fixture of opentitan's four thousand files has
|
||||
/// no business in a unit-test suite. The exact pin for that is
|
||||
/// `undriven_net`'s `the_project_is_asked_only_about_the_signals_that_would_be_reported`,
|
||||
/// which counts the questions instead of timing them
|
||||
/// (`docs/features/didopen-cost/README.md`).
|
||||
///
|
||||
/// Best of three distinct buffers: the first open of a process pays cold code
|
||||
/// paths that have nothing to do with the buffer, and a wall-clock assertion
|
||||
/// that cannot tolerate one scheduling hiccup is a flake, not a pin.
|
||||
#[test]
|
||||
fn opening_a_two_thousand_line_buffer_does_not_delay_the_request_behind_it() {
|
||||
let dir = temp_dir("didopen_cost");
|
||||
indexed_neighbours(&dir, 40);
|
||||
let mut generated = Vec::new();
|
||||
for n in 0..3 {
|
||||
let name = format!("gen{n}");
|
||||
// The generator the perf tables use: a thousand declarations, every
|
||||
// one declared, driven and read — the cheap case for the *findings*
|
||||
// and the expensive one for the walk that decides there are none.
|
||||
let text = generated_module(&name, 2_000);
|
||||
assert!(text.lines().count() >= 2_000, "the premise: a 2 000-line buffer");
|
||||
let path = dir.join(format!("{name}.sv"));
|
||||
std::fs::write(&path, &text).expect("write");
|
||||
generated.push((path, text));
|
||||
}
|
||||
let mut live = live_at(&dir);
|
||||
// A warm-up open of a small buffer, for the cold code paths.
|
||||
let warm = format!("file://{}", dir.join("pkg0.sv").display());
|
||||
open_then_hover(&mut live, 10, &warm, "package pkg0;\n localparam int K0 = 0;\nendpackage\n");
|
||||
|
||||
let mut best = std::time::Duration::MAX;
|
||||
for (n, (path, text)) in generated.iter().enumerate() {
|
||||
let uri = format!("file://{}", path.display());
|
||||
best = best.min(open_then_hover(&mut live, 20 + n as u32, &uri, text));
|
||||
}
|
||||
live.finish();
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
|
||||
assert!(
|
||||
best <= std::time::Duration::from_millis(200),
|
||||
"a didOpen of a 2 000-line buffer delayed the next request by {best:?}"
|
||||
);
|
||||
}
|
||||
|
||||
/// The other half of §46's contract: the request after an open is answered
|
||||
/// from the **buffer**, not from what is on disk.
|
||||
///
|
||||
/// Nothing about the open was deferred — it still analyzes the buffer before
|
||||
/// it returns to the loop — and this is what says so out loud. The buffer
|
||||
/// names something the file on disk does not, and declares it on a line the
|
||||
/// disk file does not, and the very first hover and the very first definition
|
||||
/// after the open both find the buffer's.
|
||||
#[test]
|
||||
fn the_first_hover_after_an_open_sees_the_buffer_and_not_the_disk() {
|
||||
let dir = temp_dir("didopen_buffer_wins");
|
||||
indexed_neighbours(&dir, 4);
|
||||
let file = dir.join("m.sv");
|
||||
std::fs::write(
|
||||
&file,
|
||||
"module m;\n localparam int ON_DISK = 1;\n logic a;\n assign a = ON_DISK;\nendmodule\n",
|
||||
)
|
||||
.expect("write");
|
||||
let uri = format!("file://{}", file.display());
|
||||
// What the editor holds: a different name, declared on a different line.
|
||||
let buffer = "module m;\n\n localparam int IN_BUFFER = 2;\n logic a;\n \
|
||||
assign a = IN_BUFFER;\nendmodule\n";
|
||||
|
||||
let mut live = live_at(&dir);
|
||||
live.send(&open_frame(&uri, buffer));
|
||||
// The cursor on `IN_BUFFER` where line 4 reads it.
|
||||
live.send(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":30,"method":"textDocument/hover","params":{{"textDocument":{{"uri":"{uri}"}},"position":{{"line":4,"character":16}}}}}}"#
|
||||
));
|
||||
let card = live.wait_for(|m| m["id"] == 30)["result"]["contents"]["value"]
|
||||
.as_str()
|
||||
.unwrap_or_default()
|
||||
.to_string();
|
||||
live.send(&format!(
|
||||
r#"{{"jsonrpc":"2.0","id":31,"method":"textDocument/definition","params":{{"textDocument":{{"uri":"{uri}"}},"position":{{"line":4,"character":16}}}}}}"#
|
||||
));
|
||||
let definition = live.wait_for(|m| m["id"] == 31);
|
||||
live.finish();
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
|
||||
assert!(card.contains("IN_BUFFER"), "the first hover did not read the buffer: {card:?}");
|
||||
assert!(!card.contains("ON_DISK"), "the first hover read the disk file: {card:?}");
|
||||
let locations = definition["result"].as_array().expect("an array of locations");
|
||||
assert_eq!(locations.len(), 1, "one declaration, got {locations:#?}");
|
||||
assert_eq!(locations[0]["range"]["start"]["line"], 2, "the buffer's line, not the disk's");
|
||||
}
|
||||
|
||||
/// And the third: the open still publishes, with no edit and no further
|
||||
/// request to trigger it.
|
||||
///
|
||||
/// **There is no debounce on the open.** §46 allowed the diagnostics to be
|
||||
/// moved onto the change debounce and to arrive one quiet period later; they
|
||||
/// were not, because the cost was never the publish — it was one rule inside
|
||||
/// it. So the guarantee is the one this server has always had: the diagnostics
|
||||
/// for an opened buffer go out inside the `didOpen`, ahead of anything queued
|
||||
/// behind it.
|
||||
#[test]
|
||||
fn an_open_still_publishes_its_diagnostics_with_no_edit_behind_it() {
|
||||
let dir = temp_dir("didopen_publishes");
|
||||
indexed_neighbours(&dir, 4);
|
||||
let file = dir.join("tabbed.sv");
|
||||
let text = "module tabbed;\n\twire a;\nendmodule\n";
|
||||
std::fs::write(&file, text).expect("write");
|
||||
let uri = format!("file://{}", file.display());
|
||||
|
||||
let mut live = live_at(&dir);
|
||||
live.send(&open_frame(&uri, text));
|
||||
let published = live.wait_for(|m| {
|
||||
m["method"] == "textDocument/publishDiagnostics" && m["params"]["uri"] == uri
|
||||
});
|
||||
live.finish();
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
|
||||
let items = published["params"]["diagnostics"].as_array().expect("a diagnostics array");
|
||||
let codes: Vec<&str> = items.iter().filter_map(|d| d["code"].as_str()).collect();
|
||||
assert!(codes.contains(&"no-tabs"), "the open published nothing about the tab: {items:#?}");
|
||||
}
|
||||
@@ -68,13 +68,6 @@ impl Rule for UndrivenNet {
|
||||
if intentionally_unused(&decl.name) || !signals.judgeable(decl) || decl.has_init {
|
||||
continue;
|
||||
}
|
||||
// A name another file in the project writes down may be driven
|
||||
// from there — a hierarchical assignment, a `force` in a
|
||||
// testbench, a `bind`-ed override — none of which this file can
|
||||
// see. Silence is the only honest answer.
|
||||
if ctx.mentioned_elsewhere(&decl.name) {
|
||||
continue;
|
||||
}
|
||||
let Some(usage) = signals.usage(decl) else { continue };
|
||||
// A `release`/`deassign` is a write that establishes no value, so
|
||||
// it is not what saves a signal from this rule.
|
||||
@@ -82,6 +75,25 @@ impl Rule for UndrivenNet {
|
||||
if signals.connected(decl) || driven || usage.reads == 0 {
|
||||
continue;
|
||||
}
|
||||
// A name another file in the project writes down may be driven
|
||||
// from there — a hierarchical assignment, a `force` in a
|
||||
// testbench, a `bind`-ed override — none of which this file can
|
||||
// see. Silence is the only honest answer.
|
||||
//
|
||||
// **Asked last, of the handful of declarations that would
|
||||
// otherwise be reported**, and not second, of every declaration in
|
||||
// the file: the oracle walks every indexed file's word list per
|
||||
// question (`WorkspaceIndex::files_mentioning`), so at the position
|
||||
// this check used to sit at, a 42 000-line buffer asked it four
|
||||
// thousand times and the rule cost 1.6 s of every `didOpen` and
|
||||
// every keystroke flush. The guards above are all local and all
|
||||
// O(1)-ish, the whole condition is one conjunction of `continue`s,
|
||||
// and `unused-signal` — the twin rule with the same oracle — has
|
||||
// always asked last. Same findings, in the same order
|
||||
// (`docs/features/didopen-cost/README.md`).
|
||||
if ctx.mentioned_elsewhere(&decl.name) {
|
||||
continue;
|
||||
}
|
||||
found.push(Violation::new(
|
||||
NAME,
|
||||
format!("`{}` is read but never driven", decl.name),
|
||||
@@ -107,17 +119,56 @@ mod tests {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// An oracle that says exactly these names are mentioned in another file.
|
||||
struct Elsewhere(&'static [&'static str]);
|
||||
/// An oracle that says exactly these names are mentioned in another file,
|
||||
/// and counts how often it was asked.
|
||||
struct Elsewhere(&'static [&'static str], std::sync::atomic::AtomicUsize);
|
||||
|
||||
impl Elsewhere {
|
||||
fn new(names: &'static [&'static str]) -> Elsewhere {
|
||||
Elsewhere(names, std::sync::atomic::AtomicUsize::new(0))
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::MentionOracle for Elsewhere {
|
||||
fn mentioned_elsewhere(&self, name: &str) -> bool {
|
||||
self.1.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
self.0.contains(&name)
|
||||
}
|
||||
}
|
||||
|
||||
/// TODO.md §46: the oracle is asked about the declarations that would
|
||||
/// otherwise be **reported**, not about every declaration in the file.
|
||||
///
|
||||
/// One question per real candidate is the whole of the fix: the server's
|
||||
/// oracle walks every indexed file's word list per question, so asking it
|
||||
/// ahead of the local guards cost 1.6 s of every `didOpen` of opentitan's
|
||||
/// 42 000-line `pinmux_reg_top.sv` — see
|
||||
/// `docs/features/didopen-cost/README.md`. Asserted on the count, because
|
||||
/// the findings alone cannot tell the two orders apart.
|
||||
#[test]
|
||||
fn the_project_is_asked_only_about_the_signals_that_would_be_reported() {
|
||||
// Ten signals: nine driven and read, one read and undriven.
|
||||
let mut src = String::from("module m (output logic q);\n");
|
||||
for k in 0..9 {
|
||||
src.push_str(&format!(" wire d{k};\n assign d{k} = 1'b0;\n"));
|
||||
}
|
||||
src.push_str(" wire lonely;\n assign q = lonely");
|
||||
for k in 0..9 {
|
||||
src.push_str(&format!(" ^ d{k}"));
|
||||
}
|
||||
src.push_str(";\nendmodule\n");
|
||||
|
||||
let oracle = Elsewhere::new(&[]);
|
||||
let ctx = LintContext::new(&src, None).with_oracle(&oracle);
|
||||
let found = UndrivenNet.check(&ctx);
|
||||
assert_eq!(found.len(), 1, "only the undriven one: {found:#?}");
|
||||
assert!(found[0].message.contains("lonely"), "{:?}", found[0].message);
|
||||
let asked = oracle.1.load(std::sync::atomic::Ordering::Relaxed);
|
||||
assert_eq!(asked, 1, "the project was asked about the driven signals too");
|
||||
}
|
||||
|
||||
fn names_in_a_project(src: &str, elsewhere: &'static [&'static str]) -> Vec<String> {
|
||||
let oracle = Elsewhere(elsewhere);
|
||||
let oracle = Elsewhere::new(elsewhere);
|
||||
let ctx = LintContext::new(src, None).with_oracle(&oracle);
|
||||
UndrivenNet
|
||||
.check(&ctx)
|
||||
|
||||
@@ -0,0 +1,565 @@
|
||||
# didOpen cost
|
||||
|
||||
## Goal
|
||||
|
||||
Take 3 (`docs/performance_take3.md` §8.4) measured that a `didOpen` of a file
|
||||
the index already covers delays the **next** request by 21–51 ms, scaling with
|
||||
file size, where take 2 measured a flat 2–4 ms. The server is a synchronous
|
||||
loop, so whatever the open does before returning is what the next request waits
|
||||
behind. TODO.md §46 asked for the cost to be measured, broken down, and for the
|
||||
largest item in it — not all of them — to be fixed, with the open returning to
|
||||
the loop fast enough that the request behind it is not left waiting and is
|
||||
still answered from up-to-date state.
|
||||
|
||||
The finding turned out to understate the problem by an order of magnitude. At
|
||||
the whole-workspace scope, opening opentitan's 42 000-line
|
||||
`pinmux_reg_top.sv` delayed the next request by **1.74 seconds**, and the whole
|
||||
of it was one lint rule asking the workspace census a question per declaration
|
||||
in the buffer. Moving that question behind the rule's own local guards — where
|
||||
its twin rule has always asked it — took the same open to **117 ms**, and took
|
||||
the take-3 rows from 51–95 ms to 3–9 ms.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **The oracle is a pure predicate.** `MentionOracle::mentioned_elsewhere` reads
|
||||
the index and returns a `bool`; it has no side effects, so where in a
|
||||
conjunction of `continue` guards it is asked cannot change what the rule
|
||||
finds. Pinned empirically as well as argued: the 0.39.0 binary and the fixed
|
||||
one publish byte-identical diagnostics for a workspace built to exercise both
|
||||
answers (below).
|
||||
- **A `didOpen`'s buffer must be analyzed before the open returns.** Every
|
||||
request flushes dirty buffers first (`Server::answer_request`), so deferring
|
||||
the *parse* to the change debounce would move the cost, not remove it, and
|
||||
would break "the first request after the open is answered from up-to-date
|
||||
state". The parse stays synchronous, and so does the publish.
|
||||
- The measurements are wire-level and on one machine (below). Sub-millisecond
|
||||
differences are not claimed; everything reported here is a factor, not a
|
||||
percent.
|
||||
- opentitan is read-only. The index cache went to a scratch
|
||||
`initializationOptions.storagePath`; `git -C ~/repo/opentitan status
|
||||
--porcelain` reported the same three pre-existing modified files before and
|
||||
after every phase.
|
||||
|
||||
## Handshakes
|
||||
|
||||
- **`vlog_linter` → the server, unchanged.** `UndrivenNet::check` returns the
|
||||
same violations, in the same order, for the same context. No rule signature,
|
||||
no registry entry, no severity and no `default_on`/`needs_workspace` answer
|
||||
moved. `lucisv check` is unaffected in every way (it has no oracle, so the
|
||||
reordered test is a constant `false` there).
|
||||
- **`WorkspaceIndex::files_mentioning` — no change requested.** Its doc comment
|
||||
records that a merged `word → files` map was measured against the per-file
|
||||
walk and rejected. That ruling stands and is not reopened here: the fix is to
|
||||
ask the question a thousand times fewer, not to make the question faster.
|
||||
What this round adds to the record is the cost of *one* question — a walk
|
||||
over every indexed file — which is what makes asking it per declaration a
|
||||
mistake at any workspace size.
|
||||
- **`Server::publish` / `flush_dirty` — untouched.** §46 allowed the open's
|
||||
diagnostics to be moved onto the change debounce. They were not; see
|
||||
"What was not done".
|
||||
|
||||
## The measurement
|
||||
|
||||
### Method
|
||||
|
||||
`scratchpad/perf46/driver.py`, take 3's method (§9 of that doc): framed
|
||||
JSON-RPC over the server's stdio, `workspace/configuration` answered with
|
||||
`{"index":{"scope":"workspace"}}`, cache warmth through
|
||||
`initializationOptions.storagePath`, positions resolved from the file text at
|
||||
run time. Per file, in one settled session: `didOpen` and a `textDocument/hover`
|
||||
at the first `module <name>` token written in the **same** flush, timed from the
|
||||
`didOpen` frame going out to the hover response coming back; then the identical
|
||||
hover again as the control. Three tries per file per binary, warm store.
|
||||
|
||||
Both binaries `cargo build --release -p lucisv_server`: the tree at f795606
|
||||
(0.43.0) and `v0.39.0` from a scratch `git worktree` (removed afterwards).
|
||||
Every server run, build and sweep went through `tools/guard.sh -m 8 -t 900`;
|
||||
no guard kill occurred.
|
||||
|
||||
Machine: Apple M1 Max, 10 cores, 64 GB, macOS 27.0, quiet (load 1–3), nothing
|
||||
else building.
|
||||
|
||||
**Note on the file set.** §46 named "the largest file in
|
||||
`hw/top_darjeeling/ip/xbar_peri/rtl/autogen/` (tl_peri_pkg.sv-class, ~42k
|
||||
lines)". In this checkout that directory holds only an 8 KB and a 3.6 KB file;
|
||||
the ~42 000-line file the plan meant is
|
||||
`hw/top_darjeeling/ip_autogen/pinmux/rtl/pinmux_reg_top.sv` (42 192 lines,
|
||||
1.3 MB), the largest `.sv` in the tree. That is the file used.
|
||||
|
||||
### Where the time went — the breakdown
|
||||
|
||||
Temporary `eprintln!` timings inside `didOpen`, `Document::new`,
|
||||
`Server::publish`, `diagnostics::all_in` and `lint_with`'s rule loop, on the
|
||||
release build; **all of them removed before finishing** (`git diff` shows only
|
||||
the rule and the tests). Milliseconds, one representative try per file.
|
||||
|
||||
| Stage | `aes.sv` 326 L | `aes_core.sv` 1 145 L | `pinmux_reg_top.sv` 42 192 L |
|
||||
|---|---:|---:|---:|
|
||||
| lex | 0.31 | 1.01 | 41.24 |
|
||||
| tolerant parse | 0.59 | 1.01 | 31.73 |
|
||||
| `collect_defines` | 0.00 | 0.01 | 0.57 |
|
||||
| `analyze` | 0.17 | 0.56 | 11.57 |
|
||||
| `resolve_external` | 0.12 | 0.32 | 4.79 |
|
||||
| line index | 0.01 | 0.03 | 0.62 |
|
||||
| **`Document::new` (the whole parse)** | **1.33** | **3.04** | **90.61** |
|
||||
| `LintRun::for_document` (discovery, waivers, memo) | 0.34 | 0.07 | 0.09 |
|
||||
| `diagnostics::all_in` (the lint pass) | 4.87 | 54.43 | **1 653.76** |
|
||||
| — of which the rule `undriven-net` | 4.38 | 52.23 | **1 608.45** |
|
||||
| — of which `multiply-driven` | — | — | 8.22 |
|
||||
| — every other rule, together | ≈0.5 | ≈2.2 | ≈37 |
|
||||
| **`didOpen` total** | **7.07** | **58.01** | **1 745.06** |
|
||||
|
||||
Two things the table settles:
|
||||
|
||||
1. **The widen is not involved.** At the whole-workspace scope every file is
|
||||
already in scope, so `widen_of` answers `Nothing` and the open costs the
|
||||
parse plus the publish and nothing else. The `didOpen` total is the sum of
|
||||
the two rows above it to within 0.2 ms.
|
||||
2. **The lint pass is 75 / 94 / 95 % of the open, and one rule is 90 / 96 /
|
||||
97 % of the lint pass.** `LintRun::for_document` — §42's discovery, the
|
||||
waiver-file reads and the once-only memo, the thing §46 guessed at — costs
|
||||
70–340 µs and is not a candidate. Neither is the completion word table or
|
||||
the semantic tokens: neither runs on an open at all.
|
||||
|
||||
### Why `undriven-net` cost that
|
||||
|
||||
The rule asked the workspace census about **every** declaration in the buffer,
|
||||
before any of its local guards had a chance to silence it:
|
||||
|
||||
```rust
|
||||
if intentionally_unused(..) || !judgeable(..) || has_init { continue }
|
||||
if ctx.mentioned_elsewhere(&decl.name) { continue } // ← was here
|
||||
let Some(usage) = signals.usage(decl) else { continue };
|
||||
if connected || driven || reads == 0 { continue }
|
||||
found.push(..)
|
||||
```
|
||||
|
||||
One `mentioned_elsewhere` is `WorkspaceIndex::files_mentioning`, a walk over
|
||||
**every indexed file** binary-searching its sorted word list — 3 976 files in
|
||||
opentitan at the workspace scope. `pinmux_reg_top.sv` has roughly four thousand
|
||||
declarations, and essentially all of them are driven, so all four thousand
|
||||
questions were asked and all four thousand answers were thrown away by the very
|
||||
next guard. `unused-signal`, the twin rule with the same oracle, has always
|
||||
asked last, which is why it never showed up in a profile.
|
||||
|
||||
The fix is to ask the question where its twin asks it: last, of the handful of
|
||||
declarations that would otherwise be reported. It is a pure reordering of a
|
||||
conjunction of `continue` guards over a side-effect-free predicate, so the
|
||||
findings and their order are unchanged.
|
||||
|
||||
### Before and after — the three §46 files
|
||||
|
||||
Wire time, `didOpen` → the hover behind it, three tries, warm store, workspace
|
||||
scope, ms.
|
||||
|
||||
| File | lines | KB | 0.39.0 | 0.43.0 **before** | 0.43.0 **after** | factor |
|
||||
|---|---:|---:|---|---|---|---:|
|
||||
| `hw/ip/aes/rtl/aes.sv` | 326 | 14 | 8.6 / 9.5 / 7.8 | 8.1 / 5.9 / 10.1 | **4.3 / 1.8 / 2.3** | ~3× |
|
||||
| `hw/ip/aes/rtl/aes_core.sv` | 1 145 | 49 | 55.8 / 65.7 / 44.4 | 56.2 / 54.0 / 48.0 | **5.9 / 6.9 / 6.3** | ~8× |
|
||||
| `…/pinmux/rtl/pinmux_reg_top.sv` | 42 192 | 1 297 | 1 725.8 / 1 694.1 / 1 751.1 | 1 742.5 / 1 740.2 / 1 756.8 | **116.5 / 116.2 / 117.3** | ~15× |
|
||||
|
||||
The control — the identical hover issued straight after the first — is
|
||||
0.09–0.20 ms for `aes.sv`, 0.12–0.19 for `aes_core.sv` and 0.46–0.60 for
|
||||
`pinmux_reg_top.sv`, before and after alike. It is the open that costs, exactly
|
||||
as take 3 said.
|
||||
|
||||
**0.39.0 measures the same as 0.43.0 before the fix.** This was never a
|
||||
regression: `undriven-net` has asked in that order since it was written. Take
|
||||
3's §8.4 comparison against take 2's 2–4 ms is therefore not a "something got
|
||||
slower" story, and take 2's client — which no longer exists — most likely
|
||||
measured a session whose scope did not switch the workspace rules on at all.
|
||||
|
||||
### Before and after — take 3's own §8.4 rows
|
||||
|
||||
Same method, whole-workspace scope. (Take 3 measured these at the *default*
|
||||
scope after the `aes.sv` widen, where the census covers ~124 files rather than
|
||||
3 976; that is why the "before" column here is worse than §8.4's 21/31/51 ms.
|
||||
The two are the same defect at two census sizes.)
|
||||
|
||||
| File | KB | take 3 §8.4 (default scope) | **before** (workspace scope) | **after** |
|
||||
|---|---:|---:|---|---|
|
||||
| `hw/ip/hmac/rtl/hmac.sv` | 33 | 21.1 | 56.8 / 42.7 / 51.0 | **4.7 / 5.7 / 3.3** |
|
||||
| `hw/ip/kmac/rtl/kmac.sv` | 53 | 31.1 | 69.3 / 72.1 / 70.6 | **7.9 / 5.3 / 8.8** |
|
||||
| `hw/ip/spi_device/rtl/spi_device.sv` | 67 | 51.2 | 94.2 / 103.4 / 88.6 | **6.0 / 8.6 / 8.7** |
|
||||
|
||||
### The ≤ 5 ms contract, honestly
|
||||
|
||||
§46 asked for "`didOpen` returns to the loop in ≤ 5 ms for a 1 000-line file".
|
||||
|
||||
- For a **generated** 1 000-line buffer the release binary is under 2 ms. Met.
|
||||
- For `aes_core.sv` — 1 145 lines but 49 KB of dense opentitan RTL, four times
|
||||
the bytes per line of a generated file — the open is **5.9–6.9 ms**, of which
|
||||
**3.0–4.4 ms is `Document::new`**: the lex, the tolerant parse, the semantic
|
||||
analysis and the external resolution. The lint pass is now 1.3 ms of it.
|
||||
So the contract is met per line and missed per byte on the densest real file
|
||||
measured, and the remainder is the parse — which cannot be deferred without
|
||||
breaking "the first request after the open is answered from up-to-date
|
||||
state". Recorded as the limit rather than met by redefining the file.
|
||||
|
||||
### Behavioural equivalence, checked on the wire
|
||||
|
||||
A two-file scratch workspace built to exercise both oracle answers: `top.sv`
|
||||
declares `lonely` (read, undriven, mentioned nowhere else) and `shared_name`
|
||||
(read, undriven, but `force`d from `other.sv`). Both binaries publish exactly
|
||||
|
||||
```
|
||||
undriven-net @1:7 `lonely` is read but never driven
|
||||
```
|
||||
|
||||
and nothing about `shared_name` — the census still silences it. Byte-identical
|
||||
between 0.39.0 and the fixed build.
|
||||
|
||||
## What was not done, and why
|
||||
|
||||
- **The open's diagnostics were not moved onto the change debounce.** §46 named
|
||||
it as a likely shape and allowed the diagnostics to arrive a debounce later.
|
||||
They still go out inside the `didOpen`, synchronously, because after the fix
|
||||
the whole publish is 0.5–1.5 ms on a real RTL file and 24 ms on a
|
||||
42 000-line one; deferring it would buy a millisecond and cost the guarantee
|
||||
that an opened file is diagnosed before anything queued behind it is
|
||||
answered. **There is no debounce on the open, and there is nothing new to
|
||||
pin about when diagnostics arrive** — pinned anyway, by
|
||||
`an_open_still_publishes_its_diagnostics_with_no_edit_behind_it`.
|
||||
- **The buffer's re-index was not skipped on a content-hash match.** §46's
|
||||
other suggested shape. It is not on the open path at all: a `didOpen` of a
|
||||
file already in scope runs no index update — `widen_of` answers `Nothing` and
|
||||
the index is untouched until a `didSave`. There was nothing to skip.
|
||||
- **`WorkspaceIndex::files_mentioning` was not given an inverted index.** See
|
||||
Handshakes: that ruling is recorded in its own doc comment and is not this
|
||||
round's to reopen. It is now the largest single item left on the open path
|
||||
for a 42 000-line file (`multiply-driven` at 8 ms is the next), but at
|
||||
~117 ms total the file is no longer the round's problem.
|
||||
- **The other 95 ms of `pinmux_reg_top.sv`'s open is the parse** (lex 41 ms,
|
||||
parse 32 ms, analyze 12 ms). Not touched; it is the price of a 1.3 MB buffer
|
||||
and it is 25× under the large-file threshold that would skip it.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] Measure first: the driver, three files, three tries, both binaries, warm
|
||||
store, workspace scope.
|
||||
- [x] Profile the open path with temporary timings; the breakdown table above;
|
||||
the timings removed (`git diff` is the rule plus the tests).
|
||||
- [x] Fix the largest item: `undriven-net` asks the census last.
|
||||
- [x] Wire-level timing test on a generated 2 000-line buffer.
|
||||
- [x] Correctness pin: the first hover **and** the first definition after an
|
||||
open see the buffer, not the disk.
|
||||
- [x] Diagnostics-still-arrive pin, with the debounce question answered (there
|
||||
is none).
|
||||
- [x] Exact regression pin: the oracle is asked once per reported candidate.
|
||||
- [x] The take-3 rows re-measured, before and after, in this README.
|
||||
- [x] Gates: `cargo fmt -p lucisv_server -p vlog_linter`, `cargo clippy
|
||||
--all-targets`, `cargo test --workspace`, `tools/corpus_check.sh`,
|
||||
`editors/vscode/smoke.js` — all guarded.
|
||||
- [ ] QA.
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-09-05 — dev (Fable 5.1)
|
||||
|
||||
- Built both binaries release: the tree at f795606, and `v0.39.0` in a scratch
|
||||
worktree under the scratchpad (removed at the end, `git worktree remove`).
|
||||
- Wrote `scratchpad/perf46/driver.py` to take 3's method and measured the three
|
||||
§46 files, three tries each, on both binaries. Both binaries measured the
|
||||
same, which is the first finding: **§8.4 is not a regression**.
|
||||
- Instrumented the open path with temporary `eprintln!` timings at four levels
|
||||
(the `didOpen` arm, `Document::new`'s six steps, `Server::publish` /
|
||||
`diagnostics_of`, and `lint_with`'s per-rule loop), measured, and removed
|
||||
every one of them. The breakdown table is above.
|
||||
- Result: the lint pass is 75–95 % of the open and `undriven-net` is 90–97 % of
|
||||
the lint pass, because it asked the workspace census once per declaration
|
||||
ahead of its own local guards. `unused-signal`, the twin rule, has always
|
||||
asked last.
|
||||
- **The fix**: move `ctx.mentioned_elsewhere` in `UndrivenNet::check` below the
|
||||
`usage` / `connected` / `driven` / `reads == 0` guards. Six lines moved, a
|
||||
comment saying why. A pure reordering of `continue`s over a side-effect-free
|
||||
predicate.
|
||||
- Checked equivalence three ways: the unit suite, the corpus check (unmoved),
|
||||
and a wire comparison of published diagnostics between the 0.39.0 binary and
|
||||
the fixed one over a workspace built so that the census both fires and does
|
||||
not. Identical.
|
||||
- Tests: one exact regression pin in the rule (a counting oracle — the findings
|
||||
alone cannot tell the two orders apart), and three wire-level tests in
|
||||
`crates/lucisv_server/tests/e2e.rs` reusing the `Live` session helper that
|
||||
was already there (`talk` writes a whole session before reading, so it cannot
|
||||
time anything).
|
||||
- **Deviation, stated plainly: the wire test's bound is 200 ms, not §46's
|
||||
25 ms.** Two reasons, both measured. (1) `cargo test` builds unoptimized, and
|
||||
one tolerant parse of a 2 000-line buffer costs ~53 ms there on its own —
|
||||
stable to a millisecond across runs — so 25 ms is unreachable in a debug
|
||||
build whatever the lint pass does; §46's 25 ms is a release figure, and the
|
||||
release binary opens the same buffer in 2–4 ms. (2) The test cannot catch the
|
||||
§46 defect at any bound: the census walk costs milliseconds over a forty-file
|
||||
fixture (measured — 53 ms with the fix, 54 ms without it, and 63 ms with the
|
||||
fixture grown to 400 files and per-file-unique names), and a fixture of
|
||||
opentitan's four thousand files has no business in the suite. So the wire
|
||||
test pins the contract — an open does not start doing something unbounded —
|
||||
and the counting oracle test in `undriven_net.rs` is the exact pin for the
|
||||
defect. Both are documented as such in their own doc comments.
|
||||
- Scratch worktree removed; driver and scratch stores deleted; opentitan
|
||||
`git status --porcelain` reports the three pre-existing files and nothing
|
||||
else.
|
||||
|
||||
**Files touched** (the plan's expected set, plus one):
|
||||
|
||||
- `crates/vlog_linter/src/rules/undriven_net.rs` — the fix and its test.
|
||||
- `crates/lucisv_server/tests/e2e.rs` — three wire tests and two helpers.
|
||||
- `docs/features/didopen-cost/README.md` — this file.
|
||||
- `TODO.md` — §46's four dev checkboxes and §44's `didOpen` line.
|
||||
|
||||
Nothing else. In particular **no server source file was changed**: the fix
|
||||
turned out to be one rule in `vlog_linter`, not anything in the open path
|
||||
itself, which is why `crates/lucisv_server/src/server/{notification,diagnostics,
|
||||
index}.rs` and `state.rs` are untouched despite being where §46 expected the
|
||||
work.
|
||||
|
||||
**Gate numbers**: `cargo fmt -p lucisv_server -p vlog_linter` clean; `cargo
|
||||
clippy --all-targets` clean; `cargo test --workspace` **3 814 passed, 0
|
||||
failed, 44 ignored** (baseline 3 810 — the four new tests);
|
||||
`tools/corpus_check.sh` **814/820**, the same six failures and the same
|
||||
`verification-error: none` / `crash: none`; `node editors/vscode/smoke.js
|
||||
target/release/lucisv-server` OK. Every one guarded at `-m 8`; no guard kill,
|
||||
and nothing came near the limit.
|
||||
|
||||
## Docs to apply at merge (lead)
|
||||
|
||||
### `docs/performance_take3.md` — annotate finding §8.4
|
||||
|
||||
Append to §8.4, after the "Reproduce" paragraph:
|
||||
|
||||
> **Fixed in 0.44.0 (TODO §46), and the finding understated it.** The delay is
|
||||
> not the widen, the diagnostics plumbing or §42's lint-run construction: it is
|
||||
> one rule. `undriven-net` asked the workspace census
|
||||
> (`WorkspaceIndex::files_mentioning`, a walk over every indexed file) once per
|
||||
> declaration in the buffer, *before* its own local guards had a chance to
|
||||
> silence it — so a file with four thousand declarations asked four thousand
|
||||
> questions and threw away four thousand answers. `unused-signal`, the twin
|
||||
> rule with the same oracle, has always asked last; `undriven-net` now does
|
||||
> too. At the whole-workspace scope, where the census covers 3 976 files rather
|
||||
> than this section's ~124, the same three files measured 51 / 70 / 95 ms
|
||||
> before and **4.6 / 7.3 / 7.8 ms** after, and opentitan's largest file,
|
||||
> `hw/top_darjeeling/ip_autogen/pinmux/rtl/pinmux_reg_top.sv` (42 192 lines),
|
||||
> went from **1 742 ms to 117 ms**. The take-2 comparison in this section
|
||||
> should be read as "take 2's session probably did not have the workspace rules
|
||||
> on", not as a regression: 0.39.0 measures the same as 0.43.0 on every cell.
|
||||
> Breakdown and method in `docs/features/didopen-cost/README.md`.
|
||||
|
||||
### `docs/perf/README.md` — a new entry
|
||||
|
||||
> ### 2026-09-05 — the `didOpen` delay (TODO §46, 0.44.0)
|
||||
>
|
||||
> Take 3's §8.4 (a `didOpen` of an already-indexed file delaying the next
|
||||
> request by 21–51 ms) measured and fixed. The breakdown, taken with temporary
|
||||
> timings on a release build and re-taken after: the tolerant parse plus the
|
||||
> semantic analysis is 1.3 / 3.0 / 91 ms for a 326- / 1 145- / 42 192-line
|
||||
> opentitan file, and the lint pass was 4.9 / 54 / 1 654 ms — of which
|
||||
> `undriven-net` alone was 4.4 / 52 / 1 608. The rule asked
|
||||
> `WorkspaceIndex::files_mentioning` (a walk over all 3 976 indexed files) once
|
||||
> per declaration, ahead of the local guards that silence almost all of them.
|
||||
> Moved behind them, where `unused-signal` has always asked.
|
||||
>
|
||||
> Wire time, `didOpen` → the request behind it, workspace scope, warm store,
|
||||
> three tries, M1 Max:
|
||||
>
|
||||
> | file | before | after |
|
||||
> |---|---|---|
|
||||
> | `aes.sv` (326 L) | 8.1 / 5.9 / 10.1 ms | 4.3 / 1.8 / 2.3 ms |
|
||||
> | `aes_core.sv` (1 145 L) | 56.2 / 54.0 / 48.0 ms | 5.9 / 6.9 / 6.3 ms |
|
||||
> | `hmac.sv` | 56.8 / 42.7 / 51.0 ms | 4.7 / 5.7 / 3.3 ms |
|
||||
> | `kmac.sv` | 69.3 / 72.1 / 70.6 ms | 7.9 / 5.3 / 8.8 ms |
|
||||
> | `spi_device.sv` | 94.2 / 103.4 / 88.6 ms | 6.0 / 8.6 / 8.7 ms |
|
||||
> | `pinmux_reg_top.sv` (42 192 L) | 1 742 / 1 740 / 1 757 ms | 116.5 / 116.2 / 117.3 ms |
|
||||
>
|
||||
> The same cost was paid on **every keystroke flush**, not just on opens: the
|
||||
> change debounce ends in the same `set_document` + `publish` pair.
|
||||
> 0.39.0 measures the same as 0.43.0 everywhere in the "before" column, so this
|
||||
> was never a regression — it is a rule that has been ordered that way since it
|
||||
> was written. Published diagnostics are byte-identical before and after.
|
||||
|
||||
## QA log
|
||||
|
||||
### 2026-09-05 — QA (Sonnet)
|
||||
|
||||
**Verdict: PASS.** No HIGH or MEDIUM findings. Two LOW/informational notes
|
||||
below; neither blocks the fix.
|
||||
|
||||
**What was verified, and how.**
|
||||
|
||||
1. **Code reading.** `git diff` of the three touched files
|
||||
(`crates/vlog_linter/src/rules/undriven_net.rs`,
|
||||
`crates/lucisv_server/tests/e2e.rs`, `TODO.md`) — a pure reordering of six
|
||||
lines plus a comment in the rule, one new unit test asserting the oracle's
|
||||
call count, and three new wire-level tests reusing the existing `Live`
|
||||
helper. Confirmed `unused-signal` (`crates/vlog_linter/src/rules/
|
||||
unused_signal.rs`) already asks its oracle last, behind
|
||||
`mentioned_outside_declarations`, unchanged by this diff — the dev's "its
|
||||
twin rule has always asked last" claim checks out by inspection.
|
||||
`WorkspaceIndex::files_mentioning`/`files_naming_in_macros`
|
||||
(`crates/vlog_semantic/src/workspace/index.rs:286-331`) confirmed
|
||||
word-exact (binary search over a sorted per-file word list, no substring
|
||||
matching) and `crates/vlog_semantic/src/words.rs` confirmed comments
|
||||
contribute no words (only `Ident`/`SystemIdent` tokens and raw text inside
|
||||
macros/directives/attributes) and macro-argument text is folded into the
|
||||
*same* union census `files_mentioning` reads — so a macro-only mention is
|
||||
expected to silence the rule exactly as a plain mention does.
|
||||
2. **Equivalence, scratch workspace.** Built both binaries release
|
||||
(`tools/guard.sh -m 8 -t 900 -- cargo build --release -p lucisv -p
|
||||
lucisv_server`): the working tree at f795606-plus-uncommitted-diff, and
|
||||
`v0.43.0` in a scratch `git worktree` (removed after). Wrote a five-file
|
||||
scratch workspace (`top.sv`, `tb.sv`, `bound_over.sv`, `iface/bus_if.sv`,
|
||||
`pkg/util_pkg.sv`) exercising every guard interaction the attack list
|
||||
named: undriven+mentioned (silent), undriven+unmentioned (reported), driven
|
||||
locally+mentioned (silent), undriven but hierarchically assigned from a
|
||||
sibling testbench (silent), `force`d through a hierarchical path from a
|
||||
sibling (silent), named only in a sibling's `bind`-ed override connection
|
||||
(silent), a plain cross-file mention (silent), a name that is only a
|
||||
*substring* of a longer identifier in a sibling (still **reported** — no
|
||||
substring match), a name that appears in a sibling only inside a `//`
|
||||
comment (still **reported** — comments aren't tokens), a name that appears
|
||||
in a sibling only as a macro argument (silent — the raw-text fold), each
|
||||
port direction, a net inside a `generate` block, a `logic` variable
|
||||
(not a `wire`), an interface, and a package. `lucisv check --select
|
||||
undriven-net .` and `--select unused-signal,undriven-net .` and a full
|
||||
`check .`, text and `--output-format json`: **byte-identical** between the
|
||||
two binaries in every case (6 violations found; `undriven_hier`,
|
||||
`undriven_forced`, `undriven_bound`, `undriven_macro_arg`,
|
||||
`undriven_mentioned`, `driven_and_mentioned` all correctly silent).
|
||||
3. **Equivalence, opentitan (read-only).** `--select undriven-net,unused-signal
|
||||
--output-format json` over `hw/ip/aes`, `hw/ip/hmac`, `hw/ip/spi_device`,
|
||||
`hw/top_darjeeling/ip_autogen/pinmux`, sets compared (order does not
|
||||
matter here since neither directory produced more than one finding):
|
||||
**identical** in all four (`aes`: 1 finding both binaries, set-equal;
|
||||
the other three: 0 findings, both). `git -C ~/repo/opentitan status
|
||||
--porcelain` before and after: only the three pre-existing files
|
||||
(`hw/ip/aes/dv/tb/tb.sv`, `hw/top_darjeeling/ip/ast/rtl/ast.sv`,
|
||||
`hw/top_earlgrey/ip/ast/rtl/ast.sv`).
|
||||
4. **The counting-oracle unit test, reverted.** Not reverted in this tree.
|
||||
Copied the dev's `undriven_net.rs` (with the fix and its new tests) into a
|
||||
fresh scratch worktree at f795606, hand-reverted only the six-line reorder
|
||||
(oracle back above the `usage`/`driven`/`connected`/`reads==0` guards,
|
||||
dev's new test left as written), and ran
|
||||
`cargo test -p vlog_linter --lib rules::undriven_net::`. Result: 16 of 17
|
||||
pass; `the_project_is_asked_only_about_the_signals_that_would_be_reported`
|
||||
**fails** — `assertion left == right failed: left: 10, right: 1` — exactly
|
||||
what asking the oracle before the local guards predicts (all ten
|
||||
signals in that fixture are `judgeable` with no initializer, so all ten
|
||||
reach the pre-fix guard). Confirms the test is an exact regression pin,
|
||||
not a tautology. Worktree removed after.
|
||||
5. **Wire timing, independently reproduced.** The dev's driver is gone, so a
|
||||
new one was written (`scratchpad/perf46_qa/driver.py`, this session's
|
||||
scratchpad) to the same shape: framed JSON-RPC over stdio,
|
||||
`initializationOptions.storagePath` for cache control, `workspace/
|
||||
didChangeConfiguration` to the workspace scope, a `workspace/symbol`
|
||||
barrier before timing, `didOpen`+`hover` in the same flush timed from send
|
||||
to the hover response, warm store, three tries. M1 Max (10 cores, 64 GB),
|
||||
`v0.43.0` (scratch worktree, removed after) vs the fixed tree's release
|
||||
build:
|
||||
|
||||
| File | 0.43.0 | fixed | factor |
|
||||
|---|---:|---:|---:|
|
||||
| `aes.sv` | 4.83 / 4.81 / 4.88 ms | 1.49 / 1.35 / 1.31 ms | ~3.4× |
|
||||
| `aes_core.sv` | 41.4 / 43.2 / 47.1 ms | 3.90 / 3.66 / 3.57 ms | ~11× |
|
||||
| `pinmux_reg_top.sv` | 1825 / 1805 / 1806 ms | 104 / 108 / 107 ms | ~17× |
|
||||
|
||||
Independently-measured numbers differ from the README's own table (a
|
||||
different driver, different process/JSON overhead, one machine) but the
|
||||
**direction and rough magnitude match closely**, `pinmux_reg_top.sv`
|
||||
especially (~17× here vs ~15× claimed, 104-108 ms here vs 116-117 ms
|
||||
claimed). The control hover (issued right after) was 0.05-0.85 ms in every
|
||||
case, before and after alike, confirming the open itself is what costs.
|
||||
Also timed a `didChange` full-text flush on `aes_core.sv` (not just
|
||||
`didOpen`): **42.6-43.5 ms (0.43.0) → 3.8-4.0 ms (fixed)** — confirms the
|
||||
README's "the same cost was paid on every keystroke flush" claim; the
|
||||
flush and the open cost the same because both end in the same
|
||||
`set_document` + `publish` pair, as documented.
|
||||
6. **`opentitan`'s 1.0 MiB index-scan cap, noted in passing (see finding
|
||||
below).** Confirmed by `window/logMessage` output during warm-up:
|
||||
`pinmux_reg_top.sv` under all three top-level variants is *skipped from
|
||||
the workspace index scan* ("skipped (1.3 MiB > 1.0 MiB cap)"), which is
|
||||
exactly take 3's "3976 indexed, 3 skipped" — not a new discovery, just
|
||||
confirms the population this round's numbers describe. The currently
|
||||
*open* buffer is unaffected by this cap (it goes through `Document::new`
|
||||
on `didOpen` regardless of size), which is why the dev's own breakdown
|
||||
table and this session's timings both see `pinmux_reg_top.sv` fully
|
||||
parsed and linted when opened.
|
||||
7. **e2e tests, 5×.** `tools/guard.sh -m 8 -t 300 -- cargo test -p
|
||||
lucisv_server --test e2e -- --test-threads=1
|
||||
opening_a_two_thousand_line_buffer_does_not_delay_the_request_behind_it
|
||||
the_first_hover_after_an_open_sees_the_buffer_and_not_the_disk
|
||||
an_open_still_publishes_its_diagnostics_with_no_edit_behind_it`: **3
|
||||
passed, 0 failed, every one of 5 runs**, 0.65-0.70 s each. Stable.
|
||||
8. **The 200 ms vs 25 ms question — my view for the lead.** The dev's
|
||||
reasoning holds up under independent measurement, not just their own
|
||||
instrumentation: (a) `target/debug/lucisv check` on a fresh 2000-line
|
||||
generated buffer (no workspace) took ~40 ms wall-clock (steady state,
|
||||
process spawn included) against `target/release/lucisv`'s ~10 ms on the
|
||||
same buffer — a debug/release ratio in the same ballpark as the dev's
|
||||
53 ms/2-4 ms claim for the parse alone; (b) a release-mode wire
|
||||
measurement of a comparable 2000-line generated buffer (matching the
|
||||
e2e test's own `generated_module` shape, 40 package neighbours, through
|
||||
the *actual LSP wire* including Python subprocess/JSON overhead) came
|
||||
back at 11.7-11.8 ms — comfortably under both 25 ms and 200 ms. This
|
||||
triangulates the dev's claim: the 200 ms bound is not hiding a live
|
||||
defect, it is debug-build parse cost that release mode does not pay, so
|
||||
asking the debug-build wire test for 25 ms would be asking it to beat a
|
||||
floor the interpreter/parser layer sets on its own. **200 ms is the
|
||||
right bound for this test**; I would not lower it, and I would not read
|
||||
"200 ms, not 25 ms" as the fix being incomplete.
|
||||
9. **Gates, guarded, re-run independently.** `cargo clippy --all-targets`:
|
||||
clean (0.12 s — fully cached, nothing to re-lint since the dev's own
|
||||
clean run). `tools/guard.sh -m 8 -t 1800 -- cargo test --workspace`:
|
||||
**3814 passed, 0 failed, 44 ignored** (summed across every crate's `test
|
||||
result:` line) — matches the dev's claimed count exactly.
|
||||
`tools/guard.sh -m 8 -t 1800 -- tools/corpus_check.sh`: **814/820
|
||||
(99.3%)**, `verification-error: none`, `crash: none`, the same six parse
|
||||
errors. `node editors/vscode/smoke.js target/release/lucisv-server`: OK
|
||||
(20 messages). No guard kill on any run.
|
||||
|
||||
**Findings.**
|
||||
|
||||
- **LOW (informational, not a defect).** While this QA was running, the
|
||||
shared working tree picked up further edits not part of the dev's
|
||||
original diff: `CHANGELOG.md`, `editors/vscode/CHANGELOG.md`,
|
||||
`editors/vscode/README.md` gained 0.44.0 release-note entries, and
|
||||
`TODO.md` gained the §46 dev-checkbox ticks (matching this README's
|
||||
Status/TODO) plus a new §47 planning section, beyond what this QA read at
|
||||
the start of its session. None of this touches the rule, the tests, or
|
||||
this README's content above this log entry, and none of it changed any
|
||||
number this QA independently re-measured — `crates/vlog_linter/src/
|
||||
rules/undriven_net.rs` and `crates/lucisv_server/tests/e2e.rs` are
|
||||
byte-identical to what was diffed at the start of this session (71 and
|
||||
204 changed lines respectively, matching exactly). Flagged so the lead
|
||||
knows the tree was not exclusively QA's for the whole session; not
|
||||
something this QA touched or reverted.
|
||||
- **LOW (context, not a defect).** `WorkspaceIndex`'s workspace-scan size cap
|
||||
(1.0 MiB) skips all three `pinmux_reg_top.sv` variants from the persistent
|
||||
cross-file census entirely. This is pre-existing and matches take 3's own
|
||||
"3976 indexed, 3 skipped" count — not introduced or affected by this
|
||||
change — but worth restating next to this round's numbers since a reader
|
||||
could otherwise wonder why a 1.3 MB file's own words never reach another
|
||||
file's `mentioned_elsewhere` answer. The *open* buffer's own analysis is
|
||||
unaffected by the cap, which is why the timings above still show the full
|
||||
parse+lint cost when the file itself is opened.
|
||||
|
||||
**Equivalence result:** identical findings, identical order, on the scratch
|
||||
fixture (text and JSON), on `lucisv check .` with no `--select`, and on all
|
||||
four opentitan directories — 0.43.0 and the fixed tree agree everywhere
|
||||
tested.
|
||||
|
||||
**Verdict: PASS.**
|
||||
|
||||
## Review
|
||||
|
||||
**2026-09-05 — lead.** Accepted; ships in 0.44.0 with §45. The plan's three
|
||||
guesses were wrong and the dev's first step — measure — is what found the
|
||||
real cause: one rule asking the whole-workspace census once per declaration
|
||||
before its local guards. The fix is six reordered lines over a
|
||||
side-effect-free predicate, with equivalence shown three ways (the suite,
|
||||
the corpus, and QA's crafted workspace covering every guard interaction
|
||||
plus four opentitan IPs byte-identical between 0.43.0 and the fix). 15× on
|
||||
the largest file, 10× on typical IPs, on every keystroke as well as every
|
||||
open. The 200 ms wire-test bound is ruled correct: it pins the contract in
|
||||
a debug build whose parse alone is ~53 ms, the exact regression pin is the
|
||||
counting-oracle unit test (verified to fail on a revert), and QA's release
|
||||
measurement of the same buffer (11.7 ms) shows the plan's 25 ms was a
|
||||
release number. No debounce was added and none is needed at 0.5–1.5 ms per
|
||||
publish. (The README lacked its Review section; added here.)
|
||||
@@ -1078,3 +1078,34 @@ for one keystroke in a 10 000-line buffer, roughly 30 ms of it lex and parse.
|
||||
That is the figure any incremental-parsing proposal has to be argued against,
|
||||
and it now exists.
|
||||
|
||||
|
||||
### 2026-09-05 — the `didOpen` delay (TODO §46, 0.44.0)
|
||||
|
||||
Take 3's §8.4 (a `didOpen` of an already-indexed file delaying the next
|
||||
request by 21–51 ms) measured and fixed. The breakdown, taken with temporary
|
||||
timings on a release build and re-taken after: the tolerant parse plus the
|
||||
semantic analysis is 1.3 / 3.0 / 91 ms for a 326- / 1 145- / 42 192-line
|
||||
opentitan file, and the lint pass was 4.9 / 54 / 1 654 ms — of which
|
||||
`undriven-net` alone was 4.4 / 52 / 1 608. The rule asked
|
||||
`WorkspaceIndex::files_mentioning` (a walk over all 3 976 indexed files) once
|
||||
per declaration, ahead of the local guards that silence almost all of them.
|
||||
Moved behind them, where `unused-signal` has always asked.
|
||||
|
||||
Wire time, `didOpen` → the request behind it, workspace scope, warm store,
|
||||
three tries, M1 Max:
|
||||
|
||||
| file | before | after |
|
||||
|---|---|---|
|
||||
| `aes.sv` (326 L) | 8.1 / 5.9 / 10.1 ms | 4.3 / 1.8 / 2.3 ms |
|
||||
| `aes_core.sv` (1 145 L) | 56.2 / 54.0 / 48.0 ms | 5.9 / 6.9 / 6.3 ms |
|
||||
| `hmac.sv` | 56.8 / 42.7 / 51.0 ms | 4.7 / 5.7 / 3.3 ms |
|
||||
| `kmac.sv` | 69.3 / 72.1 / 70.6 ms | 7.9 / 5.3 / 8.8 ms |
|
||||
| `spi_device.sv` | 94.2 / 103.4 / 88.6 ms | 6.0 / 8.6 / 8.7 ms |
|
||||
| `pinmux_reg_top.sv` (42 192 L) | 1 742 / 1 740 / 1 757 ms | 116.5 / 116.2 / 117.3 ms |
|
||||
|
||||
The same cost was paid on **every keystroke flush**, not just on opens: the
|
||||
change debounce ends in the same `set_document` + `publish` pair. 0.39.0
|
||||
measures the same as 0.43.0 everywhere in the "before" column, so this was
|
||||
never a regression — the rule had been ordered that way since it was
|
||||
written. Published diagnostics are byte-identical before and after. Full
|
||||
account: `docs/features/didopen-cost/README.md`.
|
||||
@@ -640,6 +640,24 @@ delays the next request by 51 ms, three frames.
|
||||
**Reproduce.** `bench.py widen default`, warm store; `didOpen spi_device.sv`
|
||||
then immediately `textDocument/definition` at the first `module ` token.
|
||||
|
||||
**Fixed in 0.44.0 (TODO §46), and the finding understated it.** The delay is
|
||||
not the widen, the diagnostics plumbing or §42's lint-run construction: it is
|
||||
one rule. `undriven-net` asked the workspace census
|
||||
(`WorkspaceIndex::files_mentioning`, a walk over every indexed file) once per
|
||||
declaration in the buffer, *before* its own local guards had a chance to
|
||||
silence it — so a file with four thousand declarations asked four thousand
|
||||
questions and threw away four thousand answers. `unused-signal`, the twin
|
||||
rule with the same oracle, has always asked last; `undriven-net` now does
|
||||
too. At the whole-workspace scope, where the census covers 3 976 files rather
|
||||
than this section's ~124, the same three files measured 51 / 70 / 95 ms
|
||||
before and **4.6 / 7.3 / 7.8 ms** after, and opentitan's largest file,
|
||||
`hw/top_darjeeling/ip_autogen/pinmux/rtl/pinmux_reg_top.sv` (42 192 lines),
|
||||
went from **1 742 ms to 117 ms** (QA re-derived 1 805–1 825 → 104–108). The
|
||||
take-2 comparison in this section should be read as "take 2's session
|
||||
probably did not have the workspace rules on", not as a regression: 0.39.0
|
||||
measures the same as 0.43.0 on every cell. Breakdown and method in
|
||||
`docs/features/didopen-cost/README.md`.
|
||||
|
||||
### 8.5 FINDING (low) — `lucisv check` is 6–10% slower than 0.39.0
|
||||
|
||||
`hw/ip`: 0.367 → 0.400 s mean of three (default rules), 0.420 → 0.463 s
|
||||
|
||||
Reference in new issue
Block a user