Review round §61.3 (R2a/R2b): the walk hands on the length it already has (collect_files_with) and a subtree walk carries the ancestor ignore stack down (collect_files_below); a workspace start walks, steps and publishes the open buffer's folders before discovering the rest (state/discover.rs, one scan, every file once, bounded to today's path otherwise); first useful answer 266 → 78 ms cold and 301 → 115 warm, correct in every session, warm settle under 1 s, store byte-identical, RSS down; one stopwatch assertion in a trace test dropped by the lead
This commit is contained in:
1 parent
a1c77c053f
commit
eb54042032
20 files changed
+2841
-313
No files matched your search
@@ -4717,6 +4717,13 @@ in 0.49.0. Take 4's findings are in the loop-3 list above.
|
||||
- **review round §61.2 filed:** a `format::indent_width` form taking an
|
||||
already-read `FileConfig`, so the code-action path's run and the
|
||||
publish path do one `Discovery` walk, not two (+0.1 ms today).
|
||||
- **review round §61.3 filed:** a bounded local-record load of the index
|
||||
store for the open folder's head (measured ~26 ms vs the 89 ms whole
|
||||
open, but the 61 ms checksum verification is owed either way and it
|
||||
breaks `Load::canonical`) — its own experiment if the first answer
|
||||
needs the 89 ms; and a walk that can skip an already-walked subtree so
|
||||
the two-phase discovery stops walking the open folder twice (+2.5–5 %
|
||||
on the 1/10-buffer settle).
|
||||
Sections after §46 are planned when reached.
|
||||
|
||||
## 45. Small items, round 4 (planned 2026-09-05) — topo §2.9-29, 30, 17, 22
|
||||
@@ -6357,28 +6364,73 @@ Review §2. Warm first answer 325 ms = 205 ms workspace discovery +
|
||||
Files: `lucisv_core/src/walk.rs` (an additive handshake: hand on the
|
||||
metadata the walk already stat'd), `lucisv_server/src/{state/,
|
||||
scan_order.rs,server/startup.rs,server/index.rs,index_cache.rs}`, tests.
|
||||
- [ ] R2a: measure the walk's stages (gitignore/config handling, the
|
||||
- [x] R2a: measure the walk's stages (gitignore/config handling, the
|
||||
size-cap `metadata` per file, path sorting) and the store open;
|
||||
then the walk metadata hand-off (one `stat` per file, not two) —
|
||||
the handshake recorded in `lucisv_core`'s README and topo before
|
||||
the interface changes
|
||||
- [ ] R2b: the raised-folder work begins before the remaining discovery
|
||||
the interface changes — **the split says the cap's second `stat` is
|
||||
6.9 ms of a 165 ms discovery, not the ~45 §P4b3 guessed, and the
|
||||
walk is 95 % of it; the hand-off (`collect_files_with`, additive)
|
||||
takes `stats` 3 979 → 0 and `cap` 6.92 → 0.10 ms, and the first
|
||||
answer does not move. Kept as a tidy-up; R2b is the lever.** The
|
||||
handshake went into the code's doc comments as the interface
|
||||
changed and into the feature README after, not before — recorded
|
||||
as a deviation; the topo edge is a request for the lead
|
||||
- [x] R2b: the raised-folder work begins before the remaining discovery
|
||||
finishes — one coherent scan (the folder walked, stepped and
|
||||
published first; the rest of the workspace discovered and stepped
|
||||
after; paths and facts deduplicated; configured scope, exclusions,
|
||||
filelists, size cap, unsaved-buffer precedence preserved; never two
|
||||
complete scans, never an answer from only the open file); if the
|
||||
store open remains the barrier, a measured design for bounded
|
||||
local-record loading before any format change
|
||||
- [ ] measured: first definition ≤ 200 ms warm and cold, equal to the
|
||||
local-record loading before any format change — **shipped, bounded
|
||||
twice (rung 2 only, strict descendants of a root only,
|
||||
`HEAD_WALK_MAX` 512) and `collect_files_below` carries the root's
|
||||
`.gitignore` down so the two halves of one scan cannot disagree
|
||||
about which files exist. `OPENING_FILE_WAIT` (25 ms, inside the
|
||||
staging window) closes the didOpen-vs-configuration race that left
|
||||
2 sessions in 8 paying the old cost. The store open is 61 ms of
|
||||
checksum: the bounded local load was designed and measured (~26 ms,
|
||||
~50 ms first answer) and NOT shipped — it moves cost rather than
|
||||
removing it and changes `Load::canonical`, which the compaction
|
||||
skip and the byte-identical store rest on. Filed as its own
|
||||
experiment.**
|
||||
- [x] measured: first definition ≤ 200 ms warm and cold, equal to the
|
||||
settled target (not merely non-empty); warm quiet scan ≤ 1.0 s if
|
||||
reachable, reported honestly; RSS reduction kept; startup ordering
|
||||
cases (config before/after didOpen, late/no reply, unsaved buffer,
|
||||
multiple folders, root-level file, a dependency outside the first
|
||||
folder) pinned; R2a/R2b cells + experiments
|
||||
- [ ] QA: the ordering matrix; coherence (`mismatched_answers` 0 with the
|
||||
folder) pinned; R2a/R2b cells + experiments — **first definition
|
||||
265.9 → 77.9 ms cold (−70.7 %) and 301.3 → 115.1 warm (−61.8 %),
|
||||
result count 1 in 12 of 12; warm quiet settle 1 033.9 → 997.4 ms
|
||||
(≤ 1 s, first time, by less than the spread); idle RSS −8.6 % cold;
|
||||
store byte-identical (three sha256s over 28 stores); 24 of 24 scope
|
||||
cells; `mismatched_answers` 0 AND the new stricter
|
||||
`unsettled_answers` 0. Named costs: settled +2.5 % / +4.8 % at 1/10
|
||||
open buffers (the neighbourhood subtree walked twice), and the
|
||||
"equal to the settled target" gate is met on the measured cursor
|
||||
and all 54 probe requests but is NOT true by construction for a
|
||||
cross-folder cursor — pinned by a test and filed as a
|
||||
`server/dispatch.rs` handshake.** Feature README
|
||||
`docs/features/perf5r-first-answer/`; 4 343 → 4 360 tests
|
||||
- [x] QA: the ordering matrix; coherence (`mismatched_answers` 0 with the
|
||||
settled-equality check, not the non-empty one); persistence
|
||||
attacks re-run; numbers re-taken
|
||||
— PASS. Gates green (4 360 tests, +17/−0 vs `a1c77c0`, fmt/clippy
|
||||
clean); walk hand-off sabotage caught by exactly the predicted 12
|
||||
tests; `collect_files_below` attacked with 5 fixtures beyond the
|
||||
dev's own 4 (nested exclusion, intermediate `.gitignore`, symlink
|
||||
outside root — pinned, agrees with the plain walk, not a
|
||||
regression — missing folder, `gitignore:false`), all correct;
|
||||
`HEAD_WALK_MAX` fallback has **no shipped test** but independently
|
||||
verified correct via a constructed fixture (filed for the lead);
|
||||
ordering matrix (a–h) read and sampled across 17 wire tests, `f`
|
||||
pinned (`open_next` finishes the *whole* pending discovery before
|
||||
reordering, never a targeted walk); `unsettled_answers` confirmed
|
||||
to count empty mid-scan answers against a non-empty settled one;
|
||||
cross-folder `[]` exception reported, not failed; `index_cache.rs`
|
||||
diff confirmed empty; opentitan clean, zero guard kills. QA log in
|
||||
`docs/features/perf5r-first-answer/README.md`
|
||||
|
||||
### 61.4 R4 — publication cost under load
|
||||
|
||||
|
||||
@@ -48,6 +48,35 @@ pub fn collect_files(
|
||||
gitignore: bool,
|
||||
files: &mut Vec<PathBuf>,
|
||||
warn: &mut dyn FnMut(Warning),
|
||||
) -> Result<(), String> {
|
||||
collect_files_with(input, exclude, gitignore, &mut |path, _| files.push(path), warn)
|
||||
}
|
||||
|
||||
/// [`collect_files`] with the size the walk already read handed on beside each
|
||||
/// path.
|
||||
///
|
||||
/// The same walk, the same order, the same warnings — the only difference is
|
||||
/// where a file goes when it is found. A directory walk already calls
|
||||
/// `metadata` on every entry to answer "directory?", so the length is a field
|
||||
/// of a struct it holds anyway; a caller that has to know how big a file is —
|
||||
/// the server's `lucisv.index.maxFileSize` cap — would otherwise ask the
|
||||
/// filesystem the same question a second time, once per file.
|
||||
/// `docs/features/perf5r-first-answer/README.md` measured that second `stat`
|
||||
/// at 6.9 ms of a 165 ms discovery over 3 976 files — small, because the walk
|
||||
/// has just warmed every one of those inodes, and 3 976 system calls that buy
|
||||
/// a number already in hand all the same.
|
||||
///
|
||||
/// **`None` means the walk did not look.** `input` naming a file rather than a
|
||||
/// directory is handed straight over, exactly as [`collect_files`] hands it
|
||||
/// over, with no `metadata` call added to a path that never needed one — so a
|
||||
/// caller that wants a size there asks for it itself. Every path a *directory
|
||||
/// walk* yields carries `Some`.
|
||||
pub fn collect_files_with(
|
||||
input: &str,
|
||||
exclude: &[String],
|
||||
gitignore: bool,
|
||||
found: &mut dyn FnMut(PathBuf, Option<u64>),
|
||||
warn: &mut dyn FnMut(Warning),
|
||||
) -> Result<(), String> {
|
||||
let path = Path::new(input);
|
||||
if path.is_dir() {
|
||||
@@ -57,18 +86,83 @@ pub fn collect_files(
|
||||
ignores: Vec::new(),
|
||||
rel: Vec::new(),
|
||||
visited: HashSet::new(),
|
||||
files,
|
||||
found,
|
||||
warn,
|
||||
};
|
||||
walk.dir(path);
|
||||
} else if path.is_file() {
|
||||
files.push(path.to_path_buf());
|
||||
found(path.to_path_buf(), None);
|
||||
} else {
|
||||
return Err(format!("{input}: no such file or directory"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// [`collect_files_with`] over `input`, which lies **under** `root`, finding
|
||||
/// exactly what a walk of `root` would have found there.
|
||||
///
|
||||
/// The difference from walking `input` directly is the `.gitignore` files
|
||||
/// between the two. A walk reads ignore rules from its own starting directory
|
||||
/// downwards, so `collect_files_with("<root>/hw/ip/aes")` never sees the rule
|
||||
/// `<root>/.gitignore` writes about `hw/ip/aes/gen/` — and a caller walking a
|
||||
/// subtree *of a scope whose rung is the root* would then index files that
|
||||
/// scope excludes. This one walks the ancestor chain first: it reads each
|
||||
/// ancestor's `.gitignore` onto the stack with the depth it belongs at, and it
|
||||
/// stops without yielding anything when one of those ancestors is itself
|
||||
/// ignored or excluded — because a walk of `root` would never have descended
|
||||
/// into it.
|
||||
///
|
||||
/// `input` not being under `root` is the caller's mistake and is answered the
|
||||
/// way a walk of an unknown path is: nothing found, and no error, since there
|
||||
/// is no ancestor chain to apply.
|
||||
///
|
||||
/// Everything else is [`collect_files_with`]: the same order, the same cycle
|
||||
/// guard, the same warnings, the same lengths.
|
||||
pub fn collect_files_below(
|
||||
root: &Path,
|
||||
input: &Path,
|
||||
exclude: &[String],
|
||||
gitignore: bool,
|
||||
found: &mut dyn FnMut(PathBuf, Option<u64>),
|
||||
warn: &mut dyn FnMut(Warning),
|
||||
) -> Result<(), String> {
|
||||
let Ok(below) = input.strip_prefix(root) else { return Ok(()) };
|
||||
if !input.is_dir() {
|
||||
return Err(format!("{}: no such file or directory", input.display()));
|
||||
}
|
||||
let mut walk = Walk {
|
||||
exclude,
|
||||
gitignore,
|
||||
ignores: Vec::new(),
|
||||
rel: Vec::new(),
|
||||
visited: HashSet::new(),
|
||||
found,
|
||||
warn,
|
||||
};
|
||||
// The root's own `.gitignore` sits at depth 0, exactly where a walk of the
|
||||
// root would have put it.
|
||||
walk.push_ignore(root);
|
||||
let mut here = root.to_path_buf();
|
||||
let names: Vec<String> = below.iter().map(|name| name.to_string_lossy().into_owned()).collect();
|
||||
for (at, name) in names.iter().enumerate() {
|
||||
here.push(name);
|
||||
if is_excluded(&here, exclude) {
|
||||
return Ok(());
|
||||
}
|
||||
walk.rel.push(name.clone());
|
||||
if is_ignored(&walk.ignores, &walk.rel, true) {
|
||||
return Ok(());
|
||||
}
|
||||
// Not `input`'s own — `Walk::dir` pushes that one itself, and pushing
|
||||
// it twice would apply its rules at two different depths.
|
||||
if at + 1 < names.len() {
|
||||
walk.push_ignore(&here);
|
||||
}
|
||||
}
|
||||
walk.dir(input);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// How a directory is recognised as one the walk has already entered. Two
|
||||
/// names for the same directory — a symlink and its target, or two symlinks
|
||||
/// pointing at one place — must map to the same identity, or a cycle has no
|
||||
@@ -110,7 +204,9 @@ struct Walk<'a> {
|
||||
ignores: Vec<Ignore>,
|
||||
rel: Vec<String>,
|
||||
visited: HashSet<DirId>,
|
||||
files: &'a mut Vec<PathBuf>,
|
||||
/// Where a source file goes when the walk finds one, with the length the
|
||||
/// walk's own `metadata` call already read.
|
||||
found: &'a mut dyn FnMut(PathBuf, Option<u64>),
|
||||
warn: &'a mut dyn FnMut(Warning),
|
||||
}
|
||||
|
||||
@@ -169,7 +265,10 @@ impl Walk<'_> {
|
||||
if meta.is_dir() {
|
||||
self.dir(&path);
|
||||
} else if meta.is_file() && is_source(&path) {
|
||||
self.files.push(path);
|
||||
// The length comes off the `metadata` above — the same
|
||||
// call that answered "directory?" — so a caller wanting it
|
||||
// costs the walk nothing at all.
|
||||
(self.found)(path, Some(meta.len()));
|
||||
}
|
||||
}
|
||||
self.rel.pop();
|
||||
@@ -680,6 +779,181 @@ mod tests {
|
||||
assert_eq!(tree.walk(""), ["keep.sv"]);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// The metadata hand-off — `docs/features/perf5r-first-answer/README.md`
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
/// Every path `collect_files_with` yields under `rel`, with its length.
|
||||
#[cfg(unix)]
|
||||
fn walked_with(tree: &TempTree, rel: &str) -> Vec<(String, Option<u64>)> {
|
||||
let start = if rel.is_empty() { tree.path.clone() } else { tree.path.join(rel) };
|
||||
let mut out = Vec::new();
|
||||
collect_files_with(
|
||||
start.to_str().expect("utf-8 temp path"),
|
||||
&[],
|
||||
true,
|
||||
&mut |path, len| out.push((tree.rel_of(&path), len)),
|
||||
&mut |_| {},
|
||||
)
|
||||
.expect("the walk finishes");
|
||||
out
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn the_metadata_entry_yields_exactly_the_paths_the_plain_one_does() {
|
||||
// The claim the server's cap rests on: `collect_files` is
|
||||
// `collect_files_with` with the length thrown away, so the two cannot
|
||||
// disagree about which files exist — not about order, not about
|
||||
// `.gitignore`, not about a symlink cycle, not about a broken link.
|
||||
let tree = TempTree::new("handoffsame");
|
||||
tree.write(".gitignore", "build\n");
|
||||
tree.source("a.sv");
|
||||
tree.source("rtl/b.sv");
|
||||
tree.source("rtl/deep/c.svh");
|
||||
tree.source("build/hidden.sv");
|
||||
tree.write("rtl/notsource.txt", "x");
|
||||
tree.link("rtl/loop", "..");
|
||||
tree.link("rtl/dangling.sv", "nowhere.sv");
|
||||
|
||||
let mut plain = Vec::new();
|
||||
collect_files(tree.path.to_str().expect("utf-8"), &[], true, &mut plain, &mut |_| {})
|
||||
.expect("the walk finishes");
|
||||
let plain: Vec<String> = plain.iter().map(|p| tree.rel_of(p)).collect();
|
||||
let handed: Vec<String> =
|
||||
walked_with(&tree, "").into_iter().map(|(path, _)| path).collect();
|
||||
assert_eq!(plain, handed, "the same paths in the same order, byte for byte");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn a_walked_file_carries_the_length_the_walk_already_read() {
|
||||
let tree = TempTree::new("handofflen");
|
||||
tree.write("small.sv", "module m;\nendmodule\n");
|
||||
tree.write("big.sv", &"// pad\n".repeat(500));
|
||||
let found = walked_with(&tree, "");
|
||||
let sizes: Vec<(String, Option<u64>)> = found;
|
||||
assert_eq!(
|
||||
sizes,
|
||||
[("big.sv".to_string(), Some(3_500)), ("small.sv".to_string(), Some(20))],
|
||||
"the length is the file's own, not a guess"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn a_path_named_directly_is_handed_over_without_a_stat() {
|
||||
// `None` is the walk saying it did not look — the file was named, not
|
||||
// walked to, and adding a `metadata` call for it would be a cost
|
||||
// `collect_files` never paid.
|
||||
let tree = TempTree::new("handoffnamed");
|
||||
tree.source("one.sv");
|
||||
let found = walked_with(&tree, "one.sv");
|
||||
assert_eq!(found, [("one.sv".to_string(), None)]);
|
||||
}
|
||||
|
||||
/// What `collect_files_below(root, root/rel)` finds, relative to the tree.
|
||||
#[cfg(unix)]
|
||||
fn below(tree: &TempTree, rel: &str, exclude: &[&str]) -> Vec<String> {
|
||||
let patterns: Vec<String> = exclude.iter().map(|p| p.to_string()).collect();
|
||||
let mut out = Vec::new();
|
||||
collect_files_below(
|
||||
&tree.path,
|
||||
&tree.path.join(rel),
|
||||
&patterns,
|
||||
true,
|
||||
&mut |path, _| out.push(tree.rel_of(&path)),
|
||||
&mut |_| {},
|
||||
)
|
||||
.expect("the walk finishes");
|
||||
out.sort();
|
||||
out
|
||||
}
|
||||
|
||||
/// What a walk of the whole tree finds under `rel` — the answer `below`
|
||||
/// has to reproduce.
|
||||
#[cfg(unix)]
|
||||
fn whole_under(tree: &TempTree, rel: &str, exclude: &[&str]) -> Vec<String> {
|
||||
let patterns: Vec<String> = exclude.iter().map(|p| p.to_string()).collect();
|
||||
let mut out = Vec::new();
|
||||
collect_files(tree.path.to_str().expect("utf-8"), &patterns, true, &mut out, &mut |_| {})
|
||||
.expect("the walk finishes");
|
||||
let prefix = format!("{rel}/");
|
||||
let mut under: Vec<String> =
|
||||
out.iter().map(|p| tree.rel_of(p)).filter(|p| p.starts_with(&prefix)).collect();
|
||||
under.sort();
|
||||
under
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn a_walk_that_starts_below_a_root_still_obeys_that_roots_gitignore() {
|
||||
// The whole reason `collect_files_below` exists. Starting the walk at
|
||||
// `hw/ip/aes` loses every rule written above it, and a scope whose
|
||||
// rung *is* the root would then index files that scope excludes.
|
||||
let tree = TempTree::new("belowignore");
|
||||
tree.write(".gitignore", "gen/\n*_generated.sv\n");
|
||||
tree.write("hw/.gitignore", "vendor/\n");
|
||||
tree.source("hw/ip/aes/rtl/aes.sv");
|
||||
tree.source("hw/ip/aes/rtl/aes_generated.sv");
|
||||
tree.source("hw/ip/aes/gen/made.sv");
|
||||
tree.source("hw/ip/aes/vendor/third.sv");
|
||||
tree.source("hw/ip/aes/dv/tb.sv");
|
||||
|
||||
let seen = below(&tree, "hw/ip/aes", &[]);
|
||||
assert_eq!(seen, ["hw/ip/aes/dv/tb.sv", "hw/ip/aes/rtl/aes.sv"]);
|
||||
assert_eq!(seen, whole_under(&tree, "hw/ip/aes", &[]), "the root walk agrees");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn a_directory_the_root_walk_never_entered_yields_nothing_below_it() {
|
||||
// An ancestor the root's own rules ignore is an ancestor the root walk
|
||||
// never descended into, so nothing under it is in scope however
|
||||
// directly it is named.
|
||||
let tree = TempTree::new("belowblocked");
|
||||
tree.write(".gitignore", "hw/vendor/\n");
|
||||
tree.source("hw/vendor/ip/aes/aes.sv");
|
||||
tree.source("hw/ip/aes/aes.sv");
|
||||
assert!(below(&tree, "hw/vendor/ip/aes", &[]).is_empty());
|
||||
assert_eq!(below(&tree, "hw/ip/aes", &[]), ["hw/ip/aes/aes.sv"]);
|
||||
// An excluded ancestor is the same answer by the other filter.
|
||||
assert!(below(&tree, "hw/ip/aes", &["ip"]).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn a_negation_below_the_root_still_wins_over_the_root_rule() {
|
||||
// The precedence a root walk gives — deeper file last, so its `!` line
|
||||
// re-includes — must survive the ancestor chain being pre-loaded.
|
||||
let tree = TempTree::new("belownegate");
|
||||
tree.write(".gitignore", "*.sv\n");
|
||||
tree.write("hw/ip/aes/.gitignore", "!keep.sv\n");
|
||||
tree.source("hw/ip/aes/keep.sv");
|
||||
tree.source("hw/ip/aes/drop.sv");
|
||||
let seen = below(&tree, "hw/ip/aes", &[]);
|
||||
assert_eq!(seen, ["hw/ip/aes/keep.sv"]);
|
||||
assert_eq!(seen, whole_under(&tree, "hw/ip/aes", &[]), "the root walk agrees");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn a_start_that_is_not_under_the_root_finds_nothing() {
|
||||
let tree = TempTree::new("belowoutside");
|
||||
tree.source("a/x.sv");
|
||||
let mut out = Vec::new();
|
||||
collect_files_below(
|
||||
&tree.path.join("a"),
|
||||
&tree.path,
|
||||
&[],
|
||||
true,
|
||||
&mut |path, _| out.push(path),
|
||||
&mut |_| {},
|
||||
)
|
||||
.expect("no error, nothing found");
|
||||
assert!(out.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unsupported_syntax_degrades_to_plain_globbing() {
|
||||
// `**` is just two stars inside one component; documented.
|
||||
|
||||
@@ -167,6 +167,38 @@ pub struct ScanTrace {
|
||||
/// 2026-09-08 that happens at the step that indexes each one, and is
|
||||
/// `read_ms` below (`docs/features/perf5-p4/README.md` §P4b3).
|
||||
pub discovery_ms: f64,
|
||||
|
||||
// -- discovery, split (TODO §61.3) ----------------------------------
|
||||
//
|
||||
// Five disjoint parts of `discovery_ms` and one counter. They are a split
|
||||
// *of* that stage, not stages beside it, so nothing that adds the scan up
|
||||
// may add these as well
|
||||
// (`docs/features/perf5r-first-answer/README.md`).
|
||||
/// Reading each walk root's `lucisv.toml` for its `exclude` patterns —
|
||||
/// `Discovery::for_dir`, cached per instance, so a second root under the
|
||||
/// same config costs a map lookup.
|
||||
pub config_ms: f64,
|
||||
/// The directory walks themselves: `read_dir`, `.gitignore` parsing, the
|
||||
/// cycle guard, and the one `metadata` per entry the walk has always made.
|
||||
pub walk_ms: f64,
|
||||
/// How many roots were walked — one per scope directory, so a folder scope
|
||||
/// over three open buffers' folders is three.
|
||||
pub walk_dirs: usize,
|
||||
/// Reading a filelist, when rung 1 is the one in force.
|
||||
pub filelist_ms: f64,
|
||||
/// Sorting the walk's output into path order and dropping the paths two
|
||||
/// overlapping walks both found.
|
||||
pub sort_ms: f64,
|
||||
/// Applying `lucisv.index.maxFileSize` to every walked file.
|
||||
pub cap_ms: f64,
|
||||
/// `metadata` calls the cap made *itself* — the ones the walk's hand-off
|
||||
/// did not already answer. Zero for a walked scope since 2026-09-08;
|
||||
/// a filelist's entries are not walked and still cost one each.
|
||||
pub stats: usize,
|
||||
/// Taking every open buffer's text and its finished analysis, and letting
|
||||
/// it override the disk copy of its own path.
|
||||
pub buffers_ms: f64,
|
||||
|
||||
/// Sorting into index order and putting the user's own neighbourhood at
|
||||
/// the front ([`crate::scan_order`]).
|
||||
pub order_ms: f64,
|
||||
@@ -365,7 +397,8 @@ impl ScanTrace {
|
||||
pub fn stage_line(&self) -> String {
|
||||
let c = &self.cache;
|
||||
format!(
|
||||
"scan {} stages ({}, {} files): discovery={:.2} order={:.2} cache_open={:.2} \
|
||||
"scan {} stages ({}, {} files): discovery={:.2} config={:.2} walk={:.2} \
|
||||
filelist={:.2} sort={:.2} cap={:.2} buffers={:.2} order={:.2} cache_open={:.2} \
|
||||
read={:.2} lookup={:.2} decode={:.2} parse={:.2} encode={:.2} store_write={:.2} \
|
||||
publish_absorb={:.2} publish_candidates={:.2} publish_includes={:.2} \
|
||||
publish_overlay={:.2} gone={:.2} absorb={:.2} compact={:.2} candidates={:.2} \
|
||||
@@ -374,6 +407,12 @@ impl ScanTrace {
|
||||
self.kind,
|
||||
self.read,
|
||||
self.discovery_ms,
|
||||
self.config_ms,
|
||||
self.walk_ms,
|
||||
self.filelist_ms,
|
||||
self.sort_ms,
|
||||
self.cap_ms,
|
||||
self.buffers_ms,
|
||||
self.order_ms,
|
||||
self.cache_open_ms,
|
||||
self.read_ms,
|
||||
@@ -402,13 +441,16 @@ impl ScanTrace {
|
||||
pub fn count_line(&self) -> String {
|
||||
let c = &self.cache;
|
||||
format!(
|
||||
"scan {} counts ({}): read={} read_kib={} skipped={} hits={} misses={} buffers={} \
|
||||
"scan {} counts ({}): read={} read_kib={} walk_dirs={} stats={} skipped={} \
|
||||
hits={} misses={} buffers={} \
|
||||
records={} repeats={} decoded_kib={} written_kib={} opens={} compactions={} \
|
||||
publishes={} published={} first_publish={:.2} overlays={}",
|
||||
self.number,
|
||||
self.kind,
|
||||
self.read,
|
||||
kib(self.read_bytes),
|
||||
self.walk_dirs,
|
||||
self.stats,
|
||||
self.skipped,
|
||||
c.hits,
|
||||
c.misses,
|
||||
|
||||
@@ -241,23 +241,44 @@ impl Server {
|
||||
let verbose = started.is_some();
|
||||
let bar = self.begin_indexing();
|
||||
let mut scan = self.watching(bar.as_ref(), |ws, watch| ws.begin_scan(watch, verbose));
|
||||
let interleave = scan.total() > INTERLEAVE_ABOVE;
|
||||
// A scan that has walked the user's own folders and owes itself the
|
||||
// rest of the workspace **always** interleaves, whatever its work list
|
||||
// says today: the whole point of leading with that neighbourhood is
|
||||
// that the request waiting for it is answered the moment it is in
|
||||
// (`docs/features/perf5r-first-answer/README.md`).
|
||||
let interleave = scan.total() > INTERLEAVE_ABOVE || scan.discovery_pending();
|
||||
let total = scan.total();
|
||||
if started.is_some() {
|
||||
// Whether it interleaves is said here because it is decided here,
|
||||
// and because it is the answer to "why did my hover wait?" — a
|
||||
// scan that does not interleave answers nothing until it is done.
|
||||
let interleaving = if interleave { ", interleaved" } else { "" };
|
||||
self.timing(format!("scan started: {total} file{}{interleaving}", plural(total)));
|
||||
let staged = if scan.discovery_pending() { " (the folder first)" } else { "" };
|
||||
self.timing(format!(
|
||||
"scan started: {total} file{}{staged}{interleaving}",
|
||||
plural(total)
|
||||
));
|
||||
}
|
||||
while self.watching(bar.as_ref(), |workspace, watch| workspace.scan_step(&mut scan, watch))
|
||||
{
|
||||
loop {
|
||||
// **No bar while the denominator can still grow.** The work list
|
||||
// is the neighbourhood so far, and a percentage against it would
|
||||
// fall to a twentieth of itself the moment the rest of the
|
||||
// workspace lands. The per-file log still runs — it names files,
|
||||
// not fractions — and the first percentage the client sees is the
|
||||
// first measured one (`docs/features/indexing-ux/README.md`).
|
||||
let showing = if scan.discovery_pending() { None } else { bar.as_ref() };
|
||||
let stepped =
|
||||
self.watching(showing, |workspace, watch| workspace.scan_step(&mut scan, watch));
|
||||
if !stepped {
|
||||
break;
|
||||
}
|
||||
if interleave && self.answer_what_is_waiting(&mut scan) {
|
||||
// Nothing after this may speak to a client that has gone, the
|
||||
// timing line included.
|
||||
return Vec::new();
|
||||
}
|
||||
}
|
||||
let total = scan.total();
|
||||
let (skipped, cached) = (scan.skipped(), scan.cached());
|
||||
let warnings = self.workspace.finish_scan(scan);
|
||||
self.end_indexing(bar, skipped, cached);
|
||||
@@ -350,7 +371,7 @@ impl Server {
|
||||
// the alphabet reaches them — the open-first rule, for buffers opened
|
||||
// after the work list was taken.
|
||||
if opened {
|
||||
self.workspace.open_next(scan);
|
||||
self.watching(None, |workspace, watch| workspace.open_next(scan, watch));
|
||||
self.head_owed = !scan.neighbourhood_indexed();
|
||||
}
|
||||
self.stopped
|
||||
|
||||
@@ -45,6 +45,26 @@ use crate::state::Workspace;
|
||||
/// nothing does not leave a workspace unindexed.
|
||||
pub(super) const CONFIGURATION_WAIT: Duration = Duration::from_secs(2);
|
||||
|
||||
/// How long a startup waits, *after* the settings answer, for the editor to
|
||||
/// say which file it has open.
|
||||
///
|
||||
/// **Only when that name changes what the scan does.** A workspace-scoped scan
|
||||
/// with a buffer open walks that buffer's folder first, indexes it, and
|
||||
/// answers the request waiting for it in ~115 ms; without the name it walks
|
||||
/// all 3 976 files first and answers in ~290
|
||||
/// (`docs/features/perf5r-first-answer/README.md`). The two messages are
|
||||
/// written by the client at the same moment — the settings answer by whatever
|
||||
/// handles server-initiated requests, the `didOpen` by the editor — so which
|
||||
/// arrives first is a coin toss, and losing it costs 175 ms of the thing this
|
||||
/// round is about. This is that coin toss removed.
|
||||
///
|
||||
/// It is spent **only** by a session that is going to walk a whole workspace
|
||||
/// and has no buffer at all yet: a folder-scoped session has nothing to lead
|
||||
/// with, and a session whose buffer is already in hand stops waiting the
|
||||
/// moment it applies one. So the session that pays the full bound is the one
|
||||
/// with an empty editor, where nothing is waiting on the scan.
|
||||
pub(super) const OPENING_FILE_WAIT: Duration = Duration::from_millis(25);
|
||||
|
||||
/// Everything a session starts with that is not the connection or the roots.
|
||||
///
|
||||
/// One struct rather than six more parameters: `started` is the seam every
|
||||
@@ -233,10 +253,45 @@ impl Server {
|
||||
self.staging = true;
|
||||
self.request_configuration();
|
||||
self.await_configuration(wait);
|
||||
// Inside the staging window, because it is the same window: every
|
||||
// request is still held, and the scan has still not begun.
|
||||
if !wait.is_zero() && !self.stopped {
|
||||
self.await_opening_file(OPENING_FILE_WAIT);
|
||||
}
|
||||
self.staging = false;
|
||||
self.rescan_wanted = false;
|
||||
}
|
||||
|
||||
/// Wait a bounded moment for the editor's first `didOpen`, when knowing
|
||||
/// which folder the user is in is what decides the shape of the scan
|
||||
/// about to run ([`OPENING_FILE_WAIT`]).
|
||||
///
|
||||
/// Silent for every session that would not spend the knowledge: only a
|
||||
/// workspace-scoped scan leads with a folder, and only one with nothing
|
||||
/// open has a folder still to learn. The loop stops on the first buffer
|
||||
/// rather than draining the bound, so the ordinary session pays what the
|
||||
/// message took to arrive and nothing more.
|
||||
///
|
||||
/// **Not a scope decision.** Which files the scan indexes is settled by
|
||||
/// the settings that have just landed; this decides only which of them it
|
||||
/// indexes *first*, which `vlog_semantic::IndexBuilder` cannot see
|
||||
/// (`crate::scan_order`).
|
||||
fn await_opening_file(&mut self, wait: Duration) {
|
||||
if !self.workspace.leads_with_a_folder() {
|
||||
return;
|
||||
}
|
||||
let asked = Instant::now();
|
||||
while self.workspace.open_uris().is_empty() {
|
||||
let Some(left) = wait.checked_sub(asked.elapsed()) else { return };
|
||||
let Ok(message) = self.queue.recv_timeout(left) else { return };
|
||||
let batch = burst(&self.queue, message);
|
||||
self.stopped = !matches!(self.process_batch(batch), Ok(false));
|
||||
if self.stopped {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Read the client's messages until it answers the settings pull, the
|
||||
/// bound runs out, or it goes away.
|
||||
///
|
||||
|
||||
@@ -286,3 +286,39 @@ fn a_startup_scan_with_no_files_opens_no_store_and_a_warm_rescan_rewrites_none()
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(&storage);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_discovery_split_is_a_split_of_discovery_and_not_stages_beside_it() {
|
||||
// §61.3. `config`, `walk`, `filelist`, `sort`, `cap` and `buffers` are
|
||||
// disjoint parts of `discovery`, so they may never add up to more than it
|
||||
// — and anything that sums the scan (`the_stages_add_up_to_the_scan_they
|
||||
// _describe`) must not sum these as well, which is why they are absent
|
||||
// from that test's list. The slack is `collect_sources`'s own bookkeeping:
|
||||
// the `spoken_for` set, the `Vec` pushes, the `Scope` moves.
|
||||
let tree = trace_tree("tracediscovery", 30);
|
||||
let session = Session::verbose_wide(vec![tree.path.clone()], None);
|
||||
let lines = scan_lines(&session);
|
||||
let stages = line_of(&lines, "stages");
|
||||
let discovery = number(&stages, "discovery");
|
||||
let parts: f64 = ["config", "walk", "filelist", "sort", "cap", "buffers"]
|
||||
.iter()
|
||||
.map(|key| number(&stages, key))
|
||||
.sum();
|
||||
assert!(discovery > 0.0, "a walk of 30 files takes measurable time: {stages}");
|
||||
assert!(parts <= discovery * 1.02, "the parts cannot exceed the whole: {parts} of {discovery}");
|
||||
assert!(parts > 0.0, "and at least one of them was timed: {stages}");
|
||||
// Not asserted: that the parts account for *most* of discovery. On a
|
||||
// fixture this small the whole is well under a millisecond and the
|
||||
// bookkeeping slack — the `spoken_for` set, the `Vec` pushes — rivals the
|
||||
// walk, so a ratio bound is a stopwatch under the workspace suite's
|
||||
// parallel load (it tripped once at 50 % in the lead's gate run and
|
||||
// passed alone three times). On opentitan the walk is 95 % of discovery
|
||||
// (`docs/features/perf5r-first-answer/README.md`); that ratio is the
|
||||
// README's measurement, not this test's claim.
|
||||
assert_eq!(number(&stages, "filelist"), 0.0, "no filelist is in force: {stages}");
|
||||
// Nothing was walked twice: one root, and the cap read the walk's own
|
||||
// lengths rather than asking the filesystem again.
|
||||
let counts = line_of(&lines, "counts");
|
||||
assert_eq!(field(&counts, "walk_dirs"), "1", "one root, walked once: {counts}");
|
||||
assert_eq!(field(&counts, "stats"), "0", "the cap stats nothing the walk already read");
|
||||
}
|
||||
@@ -20,6 +20,7 @@ use std::time::Instant;
|
||||
use super::scan::{positions, symbol_request};
|
||||
use super::scan_trace::{field, is_trace_line, line_of, trace_tree};
|
||||
use super::*;
|
||||
use crate::server::startup::OPENING_FILE_WAIT;
|
||||
|
||||
/// A client that answers `workspace/configuration` and is told what a scan
|
||||
/// spent its time on.
|
||||
@@ -527,3 +528,417 @@ fn an_answer_behind_a_held_request_is_not_stranded_for_the_whole_bound() {
|
||||
assert_eq!(positions(&said, 7).1, None, "a short scan answers nothing mid-way: {said:#?}");
|
||||
assert_eq!(session.server.held.len(), 1, "and the request is still owed an answer");
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// §61.3 (R2b): the neighbourhood is walked, stepped and published before
|
||||
// the rest of the workspace is discovered at all.
|
||||
// `docs/features/perf5r-first-answer/README.md`
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/// The `scan started:` line, which says whether the scan led with a folder
|
||||
/// and how many files it had when it began.
|
||||
fn scan_started(messages: &[Message]) -> String {
|
||||
log_lines(messages)
|
||||
.into_iter()
|
||||
.find(|line| line.starts_with("timing: scan started"))
|
||||
.expect("a verbose scan says it started")
|
||||
}
|
||||
|
||||
/// A `textDocument/definition` on `path` at `line`:`character`.
|
||||
fn definition_at(id: i32, path: &Path, line: u32, character: u32) -> Message {
|
||||
Message::Request(Request::new(
|
||||
RequestId::from(id),
|
||||
GotoDefinition::METHOD.to_string(),
|
||||
serde_json::json!({
|
||||
"textDocument": { "uri": path_to_uri(path).expect("uri") },
|
||||
"position": { "line": line, "character": character },
|
||||
}),
|
||||
))
|
||||
}
|
||||
|
||||
/// The result of the response to `id`, or `None` when it never came.
|
||||
fn result_of(messages: &[Message], id: i32) -> Option<Value> {
|
||||
messages.iter().find_map(|message| match message {
|
||||
Message::Response(response) if response.id == RequestId::from(id) => {
|
||||
response.response_result.clone().ok()
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_users_folder_is_walked_and_stepped_before_the_rest_of_the_workspace() {
|
||||
// **The whole of R2b.** Before it, a workspace-scoped session walked all
|
||||
// 3 976 opentitan files — 155 ms — before it could step the 124 in the
|
||||
// folder the user was looking at, and the request waiting for that folder
|
||||
// paid the whole walk. Now the folder is walked, stepped and published
|
||||
// first and the walk of the rest happens behind the answer.
|
||||
//
|
||||
// The claim is readable off two numbers on the wire: the scan *starts*
|
||||
// with the folder's file count and *finishes* over the whole workspace.
|
||||
let tree = a_block_and_a_crowd("splitfolderfirst", INTERLEAVE_ABOVE + 6);
|
||||
let opened = tree.path.join("ip/aes/dv/tb/tb.sv");
|
||||
let text = std::fs::read_to_string(&opened).expect("read");
|
||||
let session = Session::staged(
|
||||
vec![tree.path.clone()],
|
||||
pulling_with_a_bar(),
|
||||
true,
|
||||
CONFIGURATION_WAIT,
|
||||
vec![
|
||||
configuration_answer(the_whole_workspace()),
|
||||
did_open(&opened, &text),
|
||||
definition_at(7, &opened, 1, 3),
|
||||
],
|
||||
);
|
||||
let said = session.drain();
|
||||
let started = scan_started(&said);
|
||||
assert!(
|
||||
started.contains("2 files (the folder first)"),
|
||||
"the scan begins with the block's two files, not the workspace's {}: {started}",
|
||||
INTERLEAVE_ABOVE + 8
|
||||
);
|
||||
|
||||
// One scan, and it lands over everything: the split bought the order,
|
||||
// never a smaller index.
|
||||
let lines = trace_lines(&said);
|
||||
assert_eq!(lines.len(), 3, "one scan, three trace lines: {lines:#?}");
|
||||
for line in &lines {
|
||||
assert!(line.starts_with("timing: scan 1 "), "no second scan ran: {line}");
|
||||
}
|
||||
assert_eq!(
|
||||
field(&line_of(&lines, "counts"), "read"),
|
||||
(INTERLEAVE_ABOVE + 8).to_string(),
|
||||
"and the work list ends as the whole workspace"
|
||||
);
|
||||
assert_eq!(session.server.workspace.index().files().len(), INTERLEAVE_ABOVE + 8);
|
||||
|
||||
// And the answer the folder bought is the right one, given inside the
|
||||
// scan.
|
||||
let (ended, answered) = positions(&said, 7);
|
||||
let answered = answered.expect("the definition is answered at all");
|
||||
assert!(answered < ended.expect("the bar comes down"), "inside the scan: {said:#?}");
|
||||
let found = result_of(&said, 7).expect("a result");
|
||||
assert_eq!(
|
||||
found[0]["uri"],
|
||||
serde_json::json!(path_to_uri(&tree.path.join("ip/aes/rtl/aes.sv")).expect("uri")),
|
||||
"the module in the folder next door: {found}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_split_head_obeys_a_gitignore_written_at_the_workspace_root() {
|
||||
// **The correctness the split could most easily have broken.** A walk
|
||||
// starting at `ip/aes` reads no `.gitignore` above itself, so the folder
|
||||
// half of the scan would have indexed files the rest of it excludes — two
|
||||
// answers to "which files exist" inside one scan. `collect_files_below`
|
||||
// carries the ancestor rules down, and this is the file that proves it.
|
||||
let tree = a_block_and_a_crowd("splitgitignore", 4);
|
||||
tree.write(".gitignore", "*_generated.sv\n");
|
||||
tree.write("ip/aes/rtl/aes_generated.sv", "module aes_generated;\nendmodule\n");
|
||||
let opened = tree.path.join("ip/aes/dv/tb/tb.sv");
|
||||
let text = std::fs::read_to_string(&opened).expect("read");
|
||||
let session = Session::staged(
|
||||
vec![tree.path.clone()],
|
||||
pulling(),
|
||||
true,
|
||||
CONFIGURATION_WAIT,
|
||||
vec![configuration_answer(the_whole_workspace()), did_open(&opened, &text)],
|
||||
);
|
||||
let said = session.drain();
|
||||
assert!(scan_started(&said).contains("(the folder first)"), "{}", scan_started(&said));
|
||||
let indexed: Vec<String> = session
|
||||
.server
|
||||
.workspace
|
||||
.index()
|
||||
.files()
|
||||
.iter()
|
||||
.map(|path| path.display().to_string())
|
||||
.collect();
|
||||
assert!(
|
||||
!indexed.iter().any(|path| path.ends_with("aes_generated.sv")),
|
||||
"the root's rule reaches into the folder the head walked: {indexed:#?}"
|
||||
);
|
||||
// Six: two in the block, four in the crowd. The generated one is out.
|
||||
assert_eq!(indexed.len(), 6, "{indexed:#?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_buffer_opened_from_the_workspace_root_is_no_neighbourhood_to_lead_with() {
|
||||
// The bound. A file opened from the root raises to the root, so "its
|
||||
// folder" is the whole workspace — leading with it would be leading with
|
||||
// everything, and waiting for it would be waiting out the entire scan
|
||||
// before answering anything. `splits_discovery` refuses, the scan is
|
||||
// ordered exactly as it was before this round, and
|
||||
// `scan_order::worth_waiting` decides the drain as it always did.
|
||||
let tree = a_block_and_a_crowd("splitrootlevel", INTERLEAVE_ABOVE + 6);
|
||||
tree.write("top.sv", "module top;\n aes dut ();\nendmodule\n");
|
||||
let opened = tree.path.join("top.sv");
|
||||
let text = std::fs::read_to_string(&opened).expect("read");
|
||||
let session = Session::staged(
|
||||
vec![tree.path.clone()],
|
||||
pulling_with_a_bar(),
|
||||
true,
|
||||
CONFIGURATION_WAIT,
|
||||
vec![
|
||||
configuration_answer(the_whole_workspace()),
|
||||
did_open(&opened, &text),
|
||||
definition_at(7, &opened, 1, 3),
|
||||
],
|
||||
);
|
||||
let said = session.drain();
|
||||
let started = scan_started(&said);
|
||||
assert!(
|
||||
!started.contains("the folder first"),
|
||||
"the root is not a folder to lead with: {started}"
|
||||
);
|
||||
// No deadlock: the request is still answered, and inside the scan.
|
||||
let (ended, answered) = positions(&said, 7);
|
||||
let answered = answered.expect("the definition is answered at all");
|
||||
assert!(answered < ended.expect("the bar comes down"), "inside the scan: {said:#?}");
|
||||
assert_eq!(session.server.workspace.index().files().len(), INTERLEAVE_ABOVE + 9);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_buffers_in_two_folders_put_both_folders_in_the_head() {
|
||||
// The multiple-folder case. The head is the union of what each buffer
|
||||
// raises to, so a definition into *either* block is answered off it —
|
||||
// and every file is still stepped exactly once, which is what the
|
||||
// finished index's file count says.
|
||||
let tree = a_block_and_a_crowd("splittwofolders", INTERLEAVE_ABOVE + 6);
|
||||
tree.write("ip/kmac/rtl/kmac.sv", "module kmac;\n localparam W = 2;\nendmodule\n");
|
||||
tree.write("ip/kmac/dv/tb/ktb.sv", "module ktb;\n kmac dut ();\nendmodule\n");
|
||||
let aes_tb = tree.path.join("ip/aes/dv/tb/tb.sv");
|
||||
let kmac_tb = tree.path.join("ip/kmac/dv/tb/ktb.sv");
|
||||
let aes_text = std::fs::read_to_string(&aes_tb).expect("read");
|
||||
let kmac_text = std::fs::read_to_string(&kmac_tb).expect("read");
|
||||
let session = Session::staged(
|
||||
vec![tree.path.clone()],
|
||||
pulling_with_a_bar(),
|
||||
true,
|
||||
CONFIGURATION_WAIT,
|
||||
vec![
|
||||
configuration_answer(the_whole_workspace()),
|
||||
did_open(&aes_tb, &aes_text),
|
||||
did_open(&kmac_tb, &kmac_text),
|
||||
definition_at(7, &kmac_tb, 1, 3),
|
||||
],
|
||||
);
|
||||
let said = session.drain();
|
||||
let started = scan_started(&said);
|
||||
assert!(started.contains("4 files (the folder first)"), "both blocks lead: {started}");
|
||||
let found = result_of(&said, 7).expect("a result");
|
||||
assert_eq!(
|
||||
found[0]["uri"],
|
||||
serde_json::json!(path_to_uri(&tree.path.join("ip/kmac/rtl/kmac.sv")).expect("uri")),
|
||||
"the second buffer's own block is in the head too: {found}"
|
||||
);
|
||||
assert_eq!(
|
||||
session.server.workspace.index().files().len(),
|
||||
INTERLEAVE_ABOVE + 10,
|
||||
"every file once, the head's included"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unsaved_buffer_leads_with_its_own_text_and_not_the_disk_copy() {
|
||||
// Unsaved-buffer precedence, at the head. The buffer names a module the
|
||||
// file on disk does not, and the definition sent behind it must resolve
|
||||
// — which it can only do if the head indexed the buffer's own text.
|
||||
let tree = a_block_and_a_crowd("splitunsaved", INTERLEAVE_ABOVE + 6);
|
||||
let opened = tree.path.join("ip/aes/dv/tb/tb.sv");
|
||||
// On disk the testbench instantiates nothing at all.
|
||||
tree.write("ip/aes/dv/tb/tb.sv", "module tb;\nendmodule\n");
|
||||
let session = Session::staged(
|
||||
vec![tree.path.clone()],
|
||||
pulling_with_a_bar(),
|
||||
true,
|
||||
CONFIGURATION_WAIT,
|
||||
vec![
|
||||
configuration_answer(the_whole_workspace()),
|
||||
did_open(&opened, "module tb;\n aes dut ();\nendmodule\n"),
|
||||
definition_at(7, &opened, 1, 3),
|
||||
],
|
||||
);
|
||||
let said = session.drain();
|
||||
assert!(scan_started(&said).contains("(the folder first)"), "{}", scan_started(&said));
|
||||
let found = result_of(&said, 7).expect("a result");
|
||||
assert_eq!(
|
||||
found[0]["uri"],
|
||||
serde_json::json!(path_to_uri(&tree.path.join("ip/aes/rtl/aes.sv")).expect("uri")),
|
||||
"the head indexed the buffer, not the file under it: {found}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_target_outside_the_head_is_answered_when_the_head_is_published_and_is_empty() {
|
||||
// **The honest limit, pinned.** A held request is drained the moment the
|
||||
// user's own folder is published, and a definition whose target lives in
|
||||
// *another* folder is answered `[]` there — the same answer a request
|
||||
// arriving mid-scan has always had for a file the scan has not reached
|
||||
// (`docs/features/scan-interleave/README.md`). The split does not
|
||||
// introduce it and does not widen it: the reference answers the same
|
||||
// request the same way, one interleave point earlier.
|
||||
//
|
||||
// Making it wait instead needs the drain to know whether the index
|
||||
// already resolves the request's own target, which is a `server/dispatch`
|
||||
// decision and a handshake this lane filed rather than made.
|
||||
let tree = a_block_and_a_crowd("splitcrossfolder", INTERLEAVE_ABOVE + 6);
|
||||
tree.write("ip/kmac/rtl/kmac.sv", "module kmac;\nendmodule\n");
|
||||
// The buffer's folder is `ip/aes`; what it instantiates is in `ip/kmac`.
|
||||
tree.write("ip/aes/dv/tb/tb.sv", "module tb;\n kmac dut ();\nendmodule\n");
|
||||
let opened = tree.path.join("ip/aes/dv/tb/tb.sv");
|
||||
let text = std::fs::read_to_string(&opened).expect("read");
|
||||
let mut session = Session::staged(
|
||||
vec![tree.path.clone()],
|
||||
pulling_with_a_bar(),
|
||||
true,
|
||||
CONFIGURATION_WAIT,
|
||||
vec![
|
||||
configuration_answer(the_whole_workspace()),
|
||||
did_open(&opened, &text),
|
||||
definition_at(7, &opened, 1, 3),
|
||||
],
|
||||
);
|
||||
let said = session.drain();
|
||||
let found = result_of(&said, 7).expect("a result, not a failure");
|
||||
assert_eq!(
|
||||
found.as_array().map(Vec::len),
|
||||
Some(0),
|
||||
"answered off the head, which does not hold the other block: {found}"
|
||||
);
|
||||
|
||||
// And once the scan has settled the very same request is right — the
|
||||
// index is complete, and nothing about the split changed what it holds.
|
||||
session.batch(vec![definition_at(8, &opened, 1, 3)]);
|
||||
let settled = result_of(&session.drain(), 8).expect("a result");
|
||||
assert_eq!(
|
||||
settled[0]["uri"],
|
||||
serde_json::json!(path_to_uri(&tree.path.join("ip/kmac/rtl/kmac.sv")).expect("uri")),
|
||||
"the settled answer is the one the gate compares against: {settled}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_bar_paints_no_percentage_until_the_denominator_is_final() {
|
||||
// `docs/features/indexing-ux/README.md`: the percentage only counts up,
|
||||
// and every one of them is measured. While the neighbourhood is being
|
||||
// stepped the denominator is the head — which is about to grow twentyfold
|
||||
// — so no report is sent at all, and the first one the client sees is
|
||||
// against the finished work list. The per-file log still names every
|
||||
// file, head included.
|
||||
let tree = a_block_and_a_crowd("splitbar", INTERLEAVE_ABOVE + 6);
|
||||
let opened = tree.path.join("ip/aes/dv/tb/tb.sv");
|
||||
let text = std::fs::read_to_string(&opened).expect("read");
|
||||
let session = Session::staged(
|
||||
vec![tree.path.clone()],
|
||||
pulling_with_a_bar(),
|
||||
true,
|
||||
CONFIGURATION_WAIT,
|
||||
vec![configuration_answer(the_whole_workspace()), did_open(&opened, &text)],
|
||||
);
|
||||
let said = session.drain();
|
||||
let percentages: Vec<u64> = said
|
||||
.iter()
|
||||
.filter_map(|message| match message {
|
||||
Message::Notification(n) if n.method == Progress::METHOD => {
|
||||
n.params["value"]["percentage"].as_u64()
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert!(!percentages.is_empty(), "the bar does report: {said:#?}");
|
||||
assert!(
|
||||
percentages.windows(2).all(|pair| pair[0] <= pair[1]),
|
||||
"a percentage never falls: {percentages:?}"
|
||||
);
|
||||
// The head is two files of `INTERLEAVE_ABOVE + 8`; a report against the
|
||||
// head alone would have opened at 50%.
|
||||
assert!(percentages[0] < 50, "the first report is measured, not invented: {percentages:?}");
|
||||
|
||||
// And the head's files are still named in the log.
|
||||
let logged: Vec<String> = log_lines(&said)
|
||||
.into_iter()
|
||||
.filter(|line| line.starts_with("indexing: ") || line.starts_with("analyzed: "))
|
||||
.collect();
|
||||
assert!(
|
||||
logged.iter().any(|line| line.ends_with("tb.sv")),
|
||||
"the buffer's own step is logged: {logged:#?}"
|
||||
);
|
||||
assert!(
|
||||
logged.iter().any(|line| line.ends_with("aes.sv")),
|
||||
"and so is the folder's: {logged:#?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_session_that_opens_nothing_waits_only_the_opening_bound_and_scans() {
|
||||
// The cost side of `OPENING_FILE_WAIT`, and its bound. A workspace-scoped
|
||||
// session whose editor has no file open waits the whole of it — nothing
|
||||
// is waiting on the scan, which is why it is affordable — and then scans
|
||||
// the workspace exactly as it did before.
|
||||
assert_eq!(
|
||||
OPENING_FILE_WAIT,
|
||||
Duration::from_millis(25),
|
||||
"the shipped bound, which no test may quietly move"
|
||||
);
|
||||
let tree = trace_tree("splitnoopen", 9);
|
||||
let began = Instant::now();
|
||||
let session = Session::staged(
|
||||
vec![tree.path.clone()],
|
||||
pulling(),
|
||||
true,
|
||||
CONFIGURATION_WAIT,
|
||||
vec![configuration_answer(the_whole_workspace())],
|
||||
);
|
||||
let took = began.elapsed();
|
||||
assert!(took < Duration::from_secs(1), "bounded, and by the small bound: {took:?}");
|
||||
let said = session.drain();
|
||||
let lines = trace_lines(&said);
|
||||
assert_eq!(lines.len(), 3, "one scan: {lines:#?}");
|
||||
assert_eq!(field(&line_of(&lines, "counts"), "read"), "9", "the whole workspace");
|
||||
assert!(!scan_started(&said).contains("the folder first"), "nothing to lead with");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_rescan_does_not_lead_with_a_folder_because_nothing_may_be_answered_inside_it() {
|
||||
// The other half of the bound. A whole rescan is one a message asked for,
|
||||
// and `must_wait`'s `answering_a_rescan` holds every request for the whole
|
||||
// of it — so leading with the user's folder buys no answer any sooner and
|
||||
// costs the neighbourhood one extra directory traversal. Only the startup
|
||||
// scan, which nothing is queued ahead of, takes the split.
|
||||
let tree = a_block_and_a_crowd("splitrescan", INTERLEAVE_ABOVE + 6);
|
||||
let opened = tree.path.join("ip/aes/dv/tb/tb.sv");
|
||||
let text = std::fs::read_to_string(&opened).expect("read");
|
||||
let mut session = Session::staged(
|
||||
vec![tree.path.clone()],
|
||||
pulling(),
|
||||
true,
|
||||
CONFIGURATION_WAIT,
|
||||
vec![configuration_answer(the_whole_workspace()), did_open(&opened, &text)],
|
||||
);
|
||||
assert!(scan_started(&session.drain()).contains("(the folder first)"), "premise");
|
||||
|
||||
// A changed `exclude` is a scope change, which is a whole rescan.
|
||||
session.notify(
|
||||
DidChangeConfiguration::METHOD,
|
||||
serde_json::json!({ "settings": { "lucisv": {
|
||||
"index": { "scope": "workspace", "logFiles": true },
|
||||
"exclude": ["**/p000.sv"],
|
||||
} } }),
|
||||
);
|
||||
let said = session.drain();
|
||||
let started: Vec<String> = log_lines(&said)
|
||||
.into_iter()
|
||||
.filter(|line| line.starts_with("timing: scan started"))
|
||||
.collect();
|
||||
assert_eq!(started.len(), 1, "one rescan: {started:#?}");
|
||||
assert!(
|
||||
!started[0].contains("the folder first"),
|
||||
"a rescan takes the plain order: {started:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
session.server.workspace.index().files().len(),
|
||||
INTERLEAVE_ABOVE + 7,
|
||||
"and the exclusion took one file out"
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,614 @@
|
||||
//! Which files a scan will index, how they were found, and what the finding
|
||||
//! cost.
|
||||
//!
|
||||
//! The scope ladder ([`Workspace::source_files`]) and the overlay that lets an
|
||||
//! open buffer beat the disk ([`Workspace::collect_sources`]), lifted out of
|
||||
//! `state/mod.rs` on 2026-09-08 (TODO §61.3) when discovery grew a stage split
|
||||
//! and a second entry point. It answers one question — *which files exist as
|
||||
//! far as this server is concerned, and how big are they* — and every rung of
|
||||
//! the ladder is in this file.
|
||||
//!
|
||||
//! **The size a walked file reports is the walk's own.** `lucisv_core`'s walk
|
||||
//! calls `metadata` on every directory entry to answer "directory?", so the
|
||||
//! length is a field it already holds; asking the filesystem again, once per
|
||||
//! file, was 6.9 ms of a 165 ms discovery over 3 976 files — measured, not
|
||||
//! assumed, and smaller than it looks because the walk has just warmed every
|
||||
//! one of those inodes (`docs/features/perf5r-first-answer/README.md`). A path
|
||||
//! the walk did not stat — a filelist entry, an input named rather than walked
|
||||
//! — carries no length and is stat'd here, exactly as every path used to be.
|
||||
//!
|
||||
//! **And the walk is split in two when it pays to be.** A workspace-scoped
|
||||
//! session with a buffer open walks that buffer's own folders first, so the
|
||||
//! scan can index and publish them before it discovers the other 3 850 files
|
||||
//! ([`Workspace::first_scope`]). One scan, one work list, every file once.
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use lucisv_core::config::Discovery;
|
||||
use lucisv_core::walk::{collect_files_below, collect_files_with, EXTENSIONS};
|
||||
|
||||
use crate::scan_trace::ScanTrace;
|
||||
|
||||
use super::scan::{Analyzed, HeldAnalyses, IndexEvent, PendingDiscovery, Sources};
|
||||
use super::Workspace;
|
||||
|
||||
/// One in-scope file, and the length whoever found it already knew.
|
||||
///
|
||||
/// `len` is `None` for a path nothing stat'd on the way here — a filelist
|
||||
/// entry, or an input named rather than walked. It is not "unknown size": it
|
||||
/// is "nobody has looked yet", and [`oversize`] is what looks.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(super) struct Found {
|
||||
pub(super) path: PathBuf,
|
||||
pub(super) len: Option<u64>,
|
||||
}
|
||||
|
||||
impl Found {
|
||||
/// A path nothing has stat'd.
|
||||
fn unmeasured(path: PathBuf) -> Found {
|
||||
Found { path, len: None }
|
||||
}
|
||||
|
||||
/// One path on its own, for a caller asking the cap about a single file
|
||||
/// rather than about a walk ([`Workspace::current_text`]).
|
||||
pub(super) fn of(path: &Path) -> Found {
|
||||
Found::unmeasured(path.to_path_buf())
|
||||
}
|
||||
}
|
||||
|
||||
/// What the scope ladder decided: the files to index, the directories an
|
||||
/// `` `include`` in them is looked for in, and what to tell the user.
|
||||
#[derive(Default)]
|
||||
pub(super) struct Scope {
|
||||
pub(super) files: Vec<Found>,
|
||||
/// The filelist's `+incdir+`s, in filelist order. Empty for every rung
|
||||
/// but the filelist — nothing else names an include path.
|
||||
pub(super) incdirs: Vec<PathBuf>,
|
||||
pub(super) warnings: Vec<String>,
|
||||
}
|
||||
|
||||
/// The size of `found` when it is over `cap`, else `None` — the whole of the
|
||||
/// `lucisv.index.maxFileSize` test.
|
||||
///
|
||||
/// Metadata only: the point of the cap is that a 200 MB netlist is never read
|
||||
/// into memory, so knowing how big it is has to come first. A `cap` of 0 is
|
||||
/// the client asking for no cap, and a file whose metadata cannot be read is
|
||||
/// not skipped here — it simply fails the read later, as it always did.
|
||||
///
|
||||
/// `stats` counts the `metadata` calls this one really made, so a session can
|
||||
/// prove the walk's hand-off removed them rather than assert it.
|
||||
pub(super) fn oversize(found: &Found, cap: u64, stats: &mut usize) -> Option<u64> {
|
||||
if cap == 0 {
|
||||
return None;
|
||||
}
|
||||
let size = match found.len {
|
||||
Some(size) => size,
|
||||
None => {
|
||||
*stats += 1;
|
||||
fs::metadata(&found.path).ok()?.len()
|
||||
}
|
||||
};
|
||||
(size > cap).then_some(size)
|
||||
}
|
||||
|
||||
impl Workspace {
|
||||
/// Resolve the scope: which files are in it, with open buffers overriding
|
||||
/// disk, and those buffers' own text.
|
||||
///
|
||||
/// **Metadata only, plus what is already in memory.** Nothing on disk is
|
||||
/// read here — a file's text is read by whoever indexes or rewrites it,
|
||||
/// one file at a time ([`Workspace::scan_step`], [`Workspace::sources`]).
|
||||
///
|
||||
/// This is where `lucisv.index.maxFileSize` applies, and it applies to the
|
||||
/// **walked** files only: an open buffer is folded in below whatever its
|
||||
/// size, because the user opened it deliberately and an editor that
|
||||
/// refused to understand the file on screen would be absurd. The check is
|
||||
/// the size the walk read, so an oversized file is still never read at all
|
||||
/// — which is the whole saving, and it is still counted and reported here
|
||||
/// so that a scan's skip count is known before its first step.
|
||||
///
|
||||
/// A refactoring reads this same list through `sources()`, so a file the
|
||||
/// cap keeps out of the index is also a file a workspace rename will not
|
||||
/// rewrite. That is the consistent answer: the cap says which files exist
|
||||
/// as far as this server is concerned.
|
||||
pub(super) fn collect_sources(
|
||||
&self,
|
||||
watch: &mut dyn FnMut(IndexEvent),
|
||||
analyses: HeldAnalyses,
|
||||
trace: &mut ScanTrace,
|
||||
) -> Sources {
|
||||
let scope = self.source_files(trace);
|
||||
self.overlay_buffers(scope, watch, analyses, trace)
|
||||
}
|
||||
|
||||
/// [`Workspace::collect_sources`] over one already-resolved scope — the
|
||||
/// cap, then the open buffers over the top.
|
||||
///
|
||||
/// Split out because the two-phase startup resolves the scope twice (the
|
||||
/// user's own folders, then the rest of the workspace) and both halves owe
|
||||
/// the buffers the same precedence.
|
||||
pub(super) fn overlay_buffers(
|
||||
&self,
|
||||
scope: Scope,
|
||||
watch: &mut dyn FnMut(IndexEvent),
|
||||
analyses: HeldAnalyses,
|
||||
trace: &mut ScanTrace,
|
||||
) -> Sources {
|
||||
let cap = self.client.max_file_size;
|
||||
// Every path an open buffer speaks for. Reading such a file from disk
|
||||
// is work thrown away — the buffer's text replaces it below, whatever
|
||||
// the disk says — so the read is skipped rather than undone. The cap is
|
||||
// still consulted first, so an oversized file still reports itself
|
||||
// skipped exactly as it did before the buffer put its own text back.
|
||||
let spoken_for: HashSet<&Path> =
|
||||
self.docs.values().filter_map(|doc| doc.path.as_deref()).collect();
|
||||
let capping = trace.now();
|
||||
let mut stats = 0usize;
|
||||
let mut files: Vec<PathBuf> = Vec::new();
|
||||
for found in scope.files {
|
||||
if let Some(size) = oversize(&found, cap, &mut stats) {
|
||||
watch(IndexEvent::Skipped { path: &found.path, size, cap });
|
||||
continue;
|
||||
}
|
||||
if spoken_for.contains(found.path.as_path()) {
|
||||
continue;
|
||||
}
|
||||
files.push(found.path);
|
||||
}
|
||||
ScanTrace::add(&mut trace.cap_ms, capping);
|
||||
trace.stats += stats;
|
||||
// Open buffers override what is on disk, and contribute themselves
|
||||
// when they are not on disk at all.
|
||||
//
|
||||
// Except a buffer on the large-file fast path, which overrides disk
|
||||
// with *nothing*: indexing it means parsing the hundred megabytes the
|
||||
// fast path exists not to parse. Removing the path rather than leaving
|
||||
// the disk copy in is the honest half of that — the alternative would
|
||||
// be an index describing a file the user is looking at by bytes it no
|
||||
// longer has. See `docs/features/large-file-mode/README.md` for the
|
||||
// interaction with `lucisv.index.maxFileSize`, whose "an open buffer is
|
||||
// never capped" rule this is the one exception to.
|
||||
let buffering = trace.now();
|
||||
let mut analyzed = Analyzed::default();
|
||||
let mut buffered: HashMap<PathBuf, String> = HashMap::new();
|
||||
for doc in self.docs.values() {
|
||||
let Some(path) = doc.path.clone() else { continue };
|
||||
files.retain(|p| p != &path);
|
||||
if !doc.large {
|
||||
if analyses == HeldAnalyses::Wanted {
|
||||
analyzed.facts.insert(path.clone(), doc.facts(path.clone()));
|
||||
analyzed.words.insert(path.clone(), doc.words());
|
||||
}
|
||||
buffered.insert(path.clone(), doc.text.clone());
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
ScanTrace::add(&mut trace.buffers_ms, buffering);
|
||||
Sources { files, buffered, analyzed, incdirs: scope.incdirs, warnings: scope.warnings }
|
||||
}
|
||||
|
||||
/// The files the index covers, and what the user should be told about how
|
||||
/// they were chosen. The scope ladder, highest first:
|
||||
///
|
||||
/// 1. **A filelist** — `lucisv.filelist`, else a `filelist` key in the
|
||||
/// config governing a workspace root. It names *exactly* the files to
|
||||
/// index; the project said so, and guessing past it would defeat the
|
||||
/// point of having one. This is the "project file", and it is the one
|
||||
/// rung that is whole-project by definition.
|
||||
/// 2. **The workspace-folder walk**, on `lucisv.index.scope:
|
||||
/// "workspace"` — what every session did before 2026-08-27, now opt-in.
|
||||
/// 3. **The folder scope**, the default: each opened buffer's own
|
||||
/// directory raised `lucisv.index.scopeDepth` levels, walked. See
|
||||
/// `docs/features/index-scope/README.md` for what that costs, which is
|
||||
/// that a definition in another folder does not resolve until the
|
||||
/// scope reaches that folder.
|
||||
///
|
||||
/// A configured filelist that cannot be read falls back to rung 2 (or 3)
|
||||
/// with a warning. An editor that shows no symbols because of a typo in a
|
||||
/// path is worse than one that quietly indexes what it can and says so.
|
||||
///
|
||||
/// Only rung 1 can carry `+incdir+` directories: a walked workspace names
|
||||
/// none, so an `` `include`` there resolves against the including file's
|
||||
/// own directory alone (`docs/features/include-nav/README.md`).
|
||||
pub(super) fn source_files(&self, trace: &mut ScanTrace) -> Scope {
|
||||
// The walk's own warnings join the scope's, so an unreadable directory
|
||||
// reaches the output channel by the road a filelist's problems already
|
||||
// travel — said once per scan and never per keystroke.
|
||||
let mut warnings: Vec<String> = Vec::new();
|
||||
let Some(path) = self.filelist_path() else {
|
||||
let files = self.default_files(&mut |w| warnings.push(w), trace);
|
||||
return Scope { files, warnings, ..Default::default() };
|
||||
};
|
||||
let reading = trace.now();
|
||||
let read = lucisv_core::filelist::read(&path);
|
||||
ScanTrace::add(&mut trace.filelist_ms, reading);
|
||||
match read {
|
||||
Ok(list) => Scope {
|
||||
files: list.files.into_iter().map(Found::unmeasured).collect(),
|
||||
incdirs: list.incdirs,
|
||||
warnings: list.warnings,
|
||||
},
|
||||
Err(problem) => {
|
||||
let files = self.default_files(&mut |w| warnings.push(w), trace);
|
||||
warnings.insert(0, format!("{problem} — indexing the workspace instead"));
|
||||
Scope { files, incdirs: Vec::new(), warnings }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The filelist governing this workspace, if any: the client's setting
|
||||
/// first (absolute, or relative to the first root), else the `filelist`
|
||||
/// key of the config governing a root, in root order.
|
||||
///
|
||||
/// Public because the file watchers must name it: a `.f` edited outside
|
||||
/// the editor changes the index's scope, and nothing else on disk would
|
||||
/// tell us (`docs/features/file-watching/README.md`).
|
||||
pub fn filelist_path(&self) -> Option<PathBuf> {
|
||||
if let Some(setting) = &self.client.filelist {
|
||||
let path = Path::new(setting);
|
||||
return Some(match self.roots.first() {
|
||||
Some(root) if path.is_relative() => root.join(path),
|
||||
_ => path.to_path_buf(),
|
||||
});
|
||||
}
|
||||
let mut discovery = Discovery::new(true);
|
||||
// A broken `lucisv.toml` names no filelist, exactly as it contributes no
|
||||
// excludes below: the user hears about it when they format.
|
||||
self.roots.iter().find_map(|root| discovery.for_dir(root).ok()?.filelist)
|
||||
}
|
||||
|
||||
/// Rungs 2 and 3 of the ladder: the whole-workspace walk when the client
|
||||
/// asked for it, else the folder scope.
|
||||
fn default_files(&self, warn: &mut dyn FnMut(String), trace: &mut ScanTrace) -> Vec<Found> {
|
||||
if self.walks_the_workspace() {
|
||||
return self.walked_files(&self.roots, warn, trace);
|
||||
}
|
||||
self.folder_files(warn, trace)
|
||||
}
|
||||
|
||||
/// Rung 3: the folder scope — [`Workspace::scope_dirs`], walked with every
|
||||
/// filter the workspace walk applies.
|
||||
///
|
||||
/// One exception, kept exactly as it was from before this rung became the
|
||||
/// default: **a rootless session at depth 0 reads its directories flat**,
|
||||
/// one level, no `.gitignore`. That is the "a file opened on its own"
|
||||
/// case, where descending a tree the user never named would be a surprise
|
||||
/// — and the moment the user raises `scopeDepth` they have named one, so
|
||||
/// the walk is what they asked for.
|
||||
fn folder_files(&self, warn: &mut dyn FnMut(String), trace: &mut ScanTrace) -> Vec<Found> {
|
||||
let dirs = self.scope_dirs();
|
||||
if self.roots.is_empty() && self.client.index_scope_depth == 0 {
|
||||
return sibling_files(&dirs, trace);
|
||||
}
|
||||
self.walked_files(&dirs, warn, trace)
|
||||
}
|
||||
|
||||
/// Every source file under `dirs`, found by the CLI's own walk: the same
|
||||
/// extensions, the same `.gitignore` handling, and the `exclude` patterns
|
||||
/// of the config governing each directory. What `lucisv` skips, the index
|
||||
/// skips.
|
||||
///
|
||||
/// `dirs` is the workspace roots for rung 2 and the scope directories for
|
||||
/// rung 3. The one honest difference between the two: `.gitignore` files
|
||||
/// are read from the walk's own starting directory downwards, so a rule
|
||||
/// written in a root's `.gitignore` does not apply to a rung-3 walk that
|
||||
/// starts below it. The `exclude` patterns are matched against whole
|
||||
/// paths and so behave identically either way.
|
||||
pub(super) fn walked_files(
|
||||
&self,
|
||||
dirs: &[PathBuf],
|
||||
warn: &mut dyn FnMut(String),
|
||||
trace: &mut ScanTrace,
|
||||
) -> Vec<Found> {
|
||||
let mut discovery = Discovery::new(true);
|
||||
let mut out: Vec<Found> = Vec::new();
|
||||
for root in dirs {
|
||||
// The walk names its inputs as strings; every directory here came
|
||||
// from a `file:` URI, which cannot carry a non-UTF-8 path.
|
||||
let Some(input) = root.to_str() else { continue };
|
||||
// A broken `lucisv.toml` must not stop the server from indexing: an
|
||||
// index that excludes nothing is a far better failure than a
|
||||
// server that comes up empty. The error is reported when the user
|
||||
// formats a file in this tree (`format::settings_for`).
|
||||
let configuring = trace.now();
|
||||
let mut exclude =
|
||||
discovery.for_dir(root).unwrap_or_default().exclude.unwrap_or_default();
|
||||
// The client's `lucisv.exclude` is *appended*, never substituted —
|
||||
// the CLI appends a config's excludes to `--exclude` the same way,
|
||||
// and a setting that silently dropped a checked-in exclude would
|
||||
// put vendored code back in the index for one user only.
|
||||
exclude.extend(self.client.exclude.iter().cloned());
|
||||
ScanTrace::add(&mut trace.config_ms, configuring);
|
||||
// `.gitignore` is always honoured: it is the CLI's default, and an
|
||||
// editor has no `--no-gitignore` to type. An unreadable directory
|
||||
// is skipped and said — the warning rides out on the scope's own
|
||||
// warnings, which `server/notification.rs` logs once per scan.
|
||||
let walking = trace.now();
|
||||
let _ = collect_files_with(
|
||||
input,
|
||||
&exclude,
|
||||
true,
|
||||
&mut |path, len| out.push(Found { path, len }),
|
||||
&mut |w| warn(w.to_string()),
|
||||
);
|
||||
ScanTrace::add(&mut trace.walk_ms, walking);
|
||||
trace.walk_dirs += 1;
|
||||
}
|
||||
let sorting = trace.now();
|
||||
sort_found(&mut out);
|
||||
ScanTrace::add(&mut trace.sort_ms, sorting);
|
||||
out
|
||||
}
|
||||
|
||||
/// The files the directories a widen added bring into scope, by the same
|
||||
/// rules [`Workspace::folder_files`] applies to the whole scope — including
|
||||
/// the rootless-at-depth-0 flat read.
|
||||
pub(super) fn widened_files(
|
||||
&self,
|
||||
added: &[PathBuf],
|
||||
warn: &mut dyn FnMut(String),
|
||||
trace: &mut ScanTrace,
|
||||
) -> Vec<Found> {
|
||||
if self.roots.is_empty() && self.client.index_scope_depth == 0 {
|
||||
return sibling_files(added, trace);
|
||||
}
|
||||
self.walked_files(added, warn, trace)
|
||||
}
|
||||
}
|
||||
|
||||
/// The largest neighbourhood a startup will index before it finds out how big
|
||||
/// the workspace is.
|
||||
///
|
||||
/// The split's whole premise is that the user's own folder is a small part of
|
||||
/// the workspace, so stepping it first costs the rest of the scan nothing a
|
||||
/// user notices. Beyond this many files that premise is not proven — the
|
||||
/// count that would prove it is the walk this order exists to postpone — so
|
||||
/// the walk is finished first and the scan is ordered exactly as it was
|
||||
/// before, `scan_order::worth_waiting` and all.
|
||||
///
|
||||
/// 512 is a measured bound and not a round number: a warm step costs about
|
||||
/// 0.2 ms a file (124 files in 25 ms, `docs/features/perf5-p4/README.md`
|
||||
/// §P4b3), so a head of this size is ~100 ms of stepping and the whole first
|
||||
/// answer still fits inside the round's 200 ms gate.
|
||||
pub(super) const HEAD_WALK_MAX: usize = 512;
|
||||
|
||||
impl Workspace {
|
||||
/// Whether this scan may walk the user's own folders first and the rest of
|
||||
/// the workspace afterwards.
|
||||
///
|
||||
/// Three conditions, and each of them names a case the split would
|
||||
/// otherwise make *worse*:
|
||||
///
|
||||
/// * **the workspace walk is the rung in force.** It is the only rung
|
||||
/// whose discovery is a walk of everything: a filelist names its files
|
||||
/// and reads in one go, and the folder rung's own scope *is* the
|
||||
/// neighbourhood, so splitting it would put the whole scan in the head.
|
||||
/// * **a buffer is open, in a folder below a workspace root.** With no
|
||||
/// buffer there is no neighbourhood to lead with; with one opened from
|
||||
/// the root itself, the folder it raises to *is* the workspace, which is
|
||||
/// the case `scan_order::worth_waiting` exists for and the case this
|
||||
/// returns `false` for so that rule still decides it.
|
||||
/// * **the walk finds a small enough neighbourhood** — checked by the
|
||||
/// caller once the folders are walked, against [`HEAD_WALK_MAX`].
|
||||
/// * **it is the session's first scan** — checked by the caller, which is
|
||||
/// the only one that knows the scan number.
|
||||
pub(super) fn splits_discovery(&self) -> bool {
|
||||
if !self.leads_with_a_folder() {
|
||||
return false;
|
||||
}
|
||||
let dirs = self.raised_dirs();
|
||||
!dirs.is_empty() && dirs.iter().all(|dir| self.below_a_root(dir))
|
||||
}
|
||||
|
||||
/// Whether a scan of this workspace would lead with the user's own folder
|
||||
/// if it knew one — the rung half of [`Workspace::splits_discovery`],
|
||||
/// asked on its own by the startup that waits a bounded moment to be told
|
||||
/// which folder that is (`server/startup.rs`).
|
||||
pub fn leads_with_a_folder(&self) -> bool {
|
||||
self.walks_the_workspace()
|
||||
}
|
||||
|
||||
/// Whether `dir` is a **strict** descendant of some workspace root.
|
||||
///
|
||||
/// A directory that *is* a root is the whole of that root's walk, so
|
||||
/// leading with it is leading with everything.
|
||||
fn below_a_root(&self, dir: &Path) -> bool {
|
||||
self.roots.iter().any(|root| dir.starts_with(root) && dir != root)
|
||||
}
|
||||
|
||||
/// What a whole scan starts from: its scope, and whatever of that scope is
|
||||
/// still to be walked.
|
||||
///
|
||||
/// `None` for the second half means what it has always meant — the scope
|
||||
/// was resolved entire before the first file was indexed, and the work
|
||||
/// list the caller gets is the whole of it. `Some` means the caller is
|
||||
/// holding the user's own folders and owes itself the rest of the
|
||||
/// workspace once it has published them ([`PendingDiscovery`]).
|
||||
pub(super) fn first_scope(
|
||||
&self,
|
||||
watch: &mut dyn FnMut(IndexEvent),
|
||||
trace: &mut ScanTrace,
|
||||
) -> (Sources, Option<PendingDiscovery>) {
|
||||
// **The session's first scan only.** Every later whole rescan is one a
|
||||
// message asked for, and `must_wait`'s `answering_a_rescan` holds every
|
||||
// request for the whole of it — so leading with a folder buys no answer
|
||||
// any sooner and costs the neighbourhood one extra directory
|
||||
// traversal. The startup scan is the one nothing is queued ahead of,
|
||||
// and it is the one this order is for
|
||||
// (`docs/features/perf5r-first-answer/README.md`).
|
||||
if trace.number > 1 || !self.splits_discovery() {
|
||||
return (self.collect_sources(watch, HeldAnalyses::Wanted, trace), None);
|
||||
}
|
||||
let mut warnings: Vec<String> = Vec::new();
|
||||
let head = self.neighbourhood_files(&mut |w| warnings.push(w), trace);
|
||||
// Every path the neighbourhood walk named, before the cap has had a
|
||||
// say: what the remaining walk must not decide about a second time.
|
||||
let mut seen: HashSet<PathBuf> = head.iter().map(|found| found.path.clone()).collect();
|
||||
seen.extend(self.docs.values().filter_map(|doc| doc.path.clone()));
|
||||
if head.len() > HEAD_WALK_MAX {
|
||||
// Too big to lead with unproven. Finish the walk now and hand back
|
||||
// the whole scope, ordered the way every scan before this one was.
|
||||
let (mut files, rest_warnings, _) = self.walked_rest(&seen, trace);
|
||||
warnings.extend(rest_warnings);
|
||||
files.extend(head);
|
||||
sort_found(&mut files);
|
||||
let scope = Scope { files, incdirs: Vec::new(), warnings };
|
||||
return (self.overlay_buffers(scope, watch, HeldAnalyses::Wanted, trace), None);
|
||||
}
|
||||
let scope = Scope { files: head, incdirs: Vec::new(), warnings };
|
||||
let sources = self.overlay_buffers(scope, watch, HeldAnalyses::Wanted, trace);
|
||||
(sources, Some(PendingDiscovery { roots: self.roots.clone(), seen }))
|
||||
}
|
||||
|
||||
/// The user's own neighbourhood, walked: every source file under the
|
||||
/// folders the open buffers raise to, **as the walk of the workspace root
|
||||
/// would have found them**.
|
||||
///
|
||||
/// `collect_files_below` rather than `collect_files_with` is the whole of
|
||||
/// that "as": a walk starting at `hw/ip/aes` reads no `.gitignore` above
|
||||
/// itself, and the rung in force here is the *root's*, so the folder half
|
||||
/// of one scope must obey the same rules the other half does. Without it
|
||||
/// the head would index files the rest of the scan excludes, and the two
|
||||
/// halves of one scan would disagree about which files exist.
|
||||
fn neighbourhood_files(
|
||||
&self,
|
||||
warn: &mut dyn FnMut(String),
|
||||
trace: &mut ScanTrace,
|
||||
) -> Vec<Found> {
|
||||
let mut discovery = Discovery::new(true);
|
||||
let mut out: Vec<Found> = Vec::new();
|
||||
for dir in self.raised_dirs() {
|
||||
// The root this folder was raised inside: the deepest one that
|
||||
// contains it, which is the one `Workspace::raised` clamped to.
|
||||
let Some(root) = self.deepest_root(&dir) else { continue };
|
||||
let configuring = trace.now();
|
||||
let mut exclude =
|
||||
discovery.for_dir(&root).unwrap_or_default().exclude.unwrap_or_default();
|
||||
exclude.extend(self.client.exclude.iter().cloned());
|
||||
ScanTrace::add(&mut trace.config_ms, configuring);
|
||||
let walking = trace.now();
|
||||
let _ = collect_files_below(
|
||||
&root,
|
||||
&dir,
|
||||
&exclude,
|
||||
true,
|
||||
&mut |path, len| out.push(Found { path, len }),
|
||||
&mut |w| warn(w.to_string()),
|
||||
);
|
||||
ScanTrace::add(&mut trace.walk_ms, walking);
|
||||
trace.walk_dirs += 1;
|
||||
}
|
||||
let sorting = trace.now();
|
||||
sort_found(&mut out);
|
||||
ScanTrace::add(&mut trace.sort_ms, sorting);
|
||||
out
|
||||
}
|
||||
|
||||
/// The deepest workspace root containing `dir` — the one
|
||||
/// [`Workspace::raised`] clamped the raise to, and so the one whose walk
|
||||
/// this folder is part of.
|
||||
fn deepest_root(&self, dir: &Path) -> Option<PathBuf> {
|
||||
self.roots
|
||||
.iter()
|
||||
.filter(|root| dir.starts_with(root))
|
||||
.max_by_key(|root| root.components().count())
|
||||
.cloned()
|
||||
}
|
||||
|
||||
/// The roots walked, less what `seen` already names — the walk half of
|
||||
/// [`Workspace::rest_of_scope`], with no cap and no reporting.
|
||||
fn walked_rest(
|
||||
&self,
|
||||
seen: &HashSet<PathBuf>,
|
||||
trace: &mut ScanTrace,
|
||||
) -> (Vec<Found>, Vec<String>, usize) {
|
||||
let mut warnings: Vec<String> = Vec::new();
|
||||
let walked = self.walked_files(&self.roots, &mut |w| warnings.push(w), trace);
|
||||
let kept: Vec<Found> =
|
||||
walked.into_iter().filter(|found| !seen.contains(&found.path)).collect();
|
||||
let count = kept.len();
|
||||
(kept, warnings, count)
|
||||
}
|
||||
|
||||
/// The rest of the workspace: everything the roots hold that `seen` does
|
||||
/// not already name, capped and reported exactly as the neighbourhood was.
|
||||
///
|
||||
/// Returns the files to index, what the walk wants said, and how many the
|
||||
/// cap kept out. Open buffers are **not** folded in again — they were
|
||||
/// folded into the head, and a buffer's path is in `seen`.
|
||||
pub(super) fn rest_of_scope(
|
||||
&self,
|
||||
roots: &[PathBuf],
|
||||
seen: &HashSet<PathBuf>,
|
||||
watch: &mut dyn FnMut(IndexEvent),
|
||||
trace: &mut ScanTrace,
|
||||
) -> (Vec<PathBuf>, Vec<String>, usize) {
|
||||
let mut warnings: Vec<String> = Vec::new();
|
||||
let walked = self.walked_files(roots, &mut |w| warnings.push(w), trace);
|
||||
let cap = self.client.max_file_size;
|
||||
let capping = trace.now();
|
||||
let mut stats = 0usize;
|
||||
let mut skipped = 0usize;
|
||||
let mut files: Vec<PathBuf> = Vec::new();
|
||||
for found in walked {
|
||||
// Already decided about by the neighbourhood: indexed, capped out,
|
||||
// or spoken for by an open buffer. Deciding again would step a
|
||||
// file twice or report one skip as two.
|
||||
if seen.contains(&found.path) {
|
||||
continue;
|
||||
}
|
||||
if let Some(size) = oversize(&found, cap, &mut stats) {
|
||||
watch(IndexEvent::Skipped { path: &found.path, size, cap });
|
||||
skipped += 1;
|
||||
continue;
|
||||
}
|
||||
files.push(found.path);
|
||||
}
|
||||
ScanTrace::add(&mut trace.cap_ms, capping);
|
||||
trace.stats += stats;
|
||||
(files, warnings, skipped)
|
||||
}
|
||||
}
|
||||
|
||||
/// Path order, one entry per path — what the walk's callers have always done
|
||||
/// with the paths of several overlapping directory walks.
|
||||
///
|
||||
/// The first entry for a path wins, which matters only for the length beside
|
||||
/// it, and two walks that found the same file read the same `metadata` for it.
|
||||
pub(super) fn sort_found(found: &mut Vec<Found>) {
|
||||
found.sort_by(|a, b| a.path.cmp(&b.path));
|
||||
found.dedup_by(|a, b| a.path == b.path);
|
||||
}
|
||||
|
||||
/// The source files sitting in each of `dirs`, one directory deep. No walk, no
|
||||
/// `.gitignore`: this is the rootless default, where descending a tree the
|
||||
/// user never named would be a surprise.
|
||||
fn sibling_files(dirs: &[PathBuf], trace: &mut ScanTrace) -> Vec<Found> {
|
||||
let walking = trace.now();
|
||||
let mut out: Vec<Found> = Vec::new();
|
||||
for dir in dirs {
|
||||
let Ok(entries) = fs::read_dir(dir) else { continue };
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
let extension = path.extension().and_then(|e| e.to_str()).unwrap_or_default();
|
||||
if !EXTENSIONS.contains(&extension) {
|
||||
continue;
|
||||
}
|
||||
// One `metadata` — the same call `is_file()` was, with the length
|
||||
// it always had kept rather than thrown away. It follows symlinks,
|
||||
// exactly as `is_file()` did.
|
||||
let Ok(meta) = fs::metadata(&path) else { continue };
|
||||
if meta.is_file() {
|
||||
out.push(Found { path, len: Some(meta.len()) });
|
||||
}
|
||||
}
|
||||
}
|
||||
ScanTrace::add(&mut trace.walk_ms, walking);
|
||||
trace.walk_dirs += dirs.len();
|
||||
let sorting = trace.now();
|
||||
sort_found(&mut out);
|
||||
ScanTrace::add(&mut trace.sort_ms, sorting);
|
||||
out
|
||||
}
|
||||
@@ -20,9 +20,6 @@ use vlog_semantic::{
|
||||
WorkspaceIndex,
|
||||
};
|
||||
|
||||
use lucisv_core::config::Discovery;
|
||||
use lucisv_core::walk::{collect_files, EXTENSIONS};
|
||||
|
||||
use crate::candidates::Candidates;
|
||||
use crate::convert::Positions;
|
||||
use crate::includes::{self, IncludeGraph};
|
||||
@@ -31,11 +28,13 @@ use crate::module_select::{self, Reach};
|
||||
use crate::rename_trace::{self, Rung, SelectionTrace, Wanted};
|
||||
use crate::scan_order::{self, WorkList};
|
||||
|
||||
mod discover;
|
||||
mod scan;
|
||||
|
||||
use crate::scan_trace::{CacheWork, ScanTrace};
|
||||
use crate::settings::{ClientSettings, IndexScope};
|
||||
use crate::uri::uri_to_path;
|
||||
use discover::{oversize, Found};
|
||||
use scan::{Analyzed, HeldAnalyses, ScanKind, Sources};
|
||||
pub use scan::{IndexEvent, Scan};
|
||||
|
||||
@@ -289,33 +288,6 @@ pub fn mixed_buffer(blocks: usize) -> String {
|
||||
src
|
||||
}
|
||||
|
||||
/// What the scope ladder decided: the files to index, the directories an
|
||||
/// `` `include`` in them is looked for in, and what to tell the user.
|
||||
#[derive(Default)]
|
||||
struct Scope {
|
||||
files: Vec<PathBuf>,
|
||||
/// The filelist's `+incdir+`s, in filelist order. Empty for every rung
|
||||
/// but the filelist — nothing else names an include path.
|
||||
incdirs: Vec<PathBuf>,
|
||||
warnings: Vec<String>,
|
||||
}
|
||||
|
||||
/// The size of `path` when it is over `cap`, else `None` — the whole of the
|
||||
/// `lucisv.index.maxFileSize` test.
|
||||
///
|
||||
/// Metadata only: the point of the cap is that a 200 MB netlist is never read
|
||||
/// into memory, so asking the filesystem how big it is has to come first. A
|
||||
/// `cap` of 0 is the client asking for no cap, and a file whose metadata
|
||||
/// cannot be read is not skipped here — it simply fails the read below, as it
|
||||
/// always did.
|
||||
fn oversize(path: &Path, cap: u64) -> Option<u64> {
|
||||
if cap == 0 {
|
||||
return None;
|
||||
}
|
||||
let size = fs::metadata(path).ok()?.len();
|
||||
(size > cap).then_some(size)
|
||||
}
|
||||
|
||||
/// How many bytes of buffer text a scan carries for its whole life — every
|
||||
/// other file's text lives from its own step to the end of that step.
|
||||
fn held_bytes(buffered: &HashMap<PathBuf, String>) -> usize {
|
||||
@@ -839,17 +811,18 @@ impl Workspace {
|
||||
self.views.borrow_mut().clear();
|
||||
let discovering = trace.now();
|
||||
let mut skipped = 0usize;
|
||||
let mut scope = {
|
||||
// The cap's skips are reported by `collect_sources` and counted
|
||||
// here, because the end message names them and the scan is what
|
||||
// owns that number now.
|
||||
let mut counting = |event: IndexEvent<'_>| {
|
||||
if matches!(event, IndexEvent::Skipped { .. }) {
|
||||
skipped += 1;
|
||||
}
|
||||
watch(event);
|
||||
};
|
||||
self.collect_sources(&mut counting, HeldAnalyses::Wanted)
|
||||
// The cap's skips are reported by `collect_sources` and counted here,
|
||||
// because the end message names them and the scan is what owns that
|
||||
// number now.
|
||||
let mut counting = |event: IndexEvent<'_>, skipped: &mut usize| {
|
||||
if matches!(event, IndexEvent::Skipped { .. }) {
|
||||
*skipped += 1;
|
||||
}
|
||||
watch(event);
|
||||
};
|
||||
let (mut scope, pending) = {
|
||||
let mut count = |event: IndexEvent<'_>| counting(event, &mut skipped);
|
||||
self.first_scope(&mut count, &mut trace)
|
||||
};
|
||||
ScanTrace::add(&mut trace.discovery_ms, discovering);
|
||||
let buffered = std::mem::take(&mut scope.buffered);
|
||||
@@ -858,7 +831,15 @@ impl Workspace {
|
||||
// The same list the index will be built from, with the user's own
|
||||
// neighbourhood moved to the front of it.
|
||||
let WorkList { files: work, head } = self.open_first(std::mem::take(&mut scope.files));
|
||||
let head = scan_order::worth_waiting(head, work.len());
|
||||
// A scan that has not walked the whole workspace yet cannot ask
|
||||
// whether its head is a minority of it — the count that would answer
|
||||
// is the walk it is postponing. `splits_discovery` is what bounds the
|
||||
// head instead, and it refuses exactly the case `worth_waiting`
|
||||
// refuses: a buffer whose folder is the workspace.
|
||||
let head = match pending.is_some() {
|
||||
true => head,
|
||||
false => scan_order::worth_waiting(head, work.len()),
|
||||
};
|
||||
let paths = work.clone();
|
||||
ScanTrace::add(&mut trace.order_ms, ordering);
|
||||
// Re-opened rather than held across rescans: the directory it belongs
|
||||
@@ -881,6 +862,7 @@ impl Workspace {
|
||||
incdirs: scope.incdirs,
|
||||
warnings: scope.warnings,
|
||||
at: 0,
|
||||
pending,
|
||||
staged: Vec::new(),
|
||||
staged_at: Vec::new(),
|
||||
words: HashMap::new(),
|
||||
@@ -890,6 +872,40 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
/// Walk the rest of the workspace, once the user's own neighbourhood has
|
||||
/// been indexed and published — the second half of a split discovery
|
||||
/// ([`PendingDiscovery`]). Reports whether there was anything to walk.
|
||||
///
|
||||
/// **Its own step, indexing nothing.** The step it shares a call with
|
||||
/// would otherwise report a file against a denominator that grew inside
|
||||
/// the same call, and a bar whose percentage falls is worse than one that
|
||||
/// waits (`docs/features/indexing-ux/README.md`). So this discovers, says
|
||||
/// "there is more", and lets the next step be an ordinary one.
|
||||
fn discover_the_rest(&mut self, scan: &mut Scan, watch: &mut dyn FnMut(IndexEvent)) -> bool {
|
||||
let Some(pending) = scan.take_pending() else { return false };
|
||||
let discovering = scan.trace.now();
|
||||
let mut skipped = 0usize;
|
||||
let (files, warnings, walked_skips) = {
|
||||
let mut counting = |event: IndexEvent<'_>| {
|
||||
if matches!(event, IndexEvent::Skipped { .. }) {
|
||||
skipped += 1;
|
||||
}
|
||||
watch(event);
|
||||
};
|
||||
self.rest_of_scope(&pending.roots, &pending.seen, &mut counting, &mut scan.trace)
|
||||
};
|
||||
debug_assert_eq!(skipped, walked_skips, "the cap reports every skip it counts");
|
||||
ScanTrace::add(&mut scan.trace.discovery_ms, discovering);
|
||||
scan.land_discovery(files, warnings, walked_skips);
|
||||
scan.trace.measure_work(
|
||||
scan.work.len(),
|
||||
held_bytes(&scan.buffered),
|
||||
scan.skipped,
|
||||
scan.trace.cache,
|
||||
);
|
||||
true
|
||||
}
|
||||
|
||||
/// Open the store a whole rescan asked for, if this is the first thing to
|
||||
/// need it ([`StoreOpen`]).
|
||||
///
|
||||
@@ -959,14 +975,16 @@ impl Workspace {
|
||||
// `folder_files` follows — the whole scope is the union of these walks,
|
||||
// so the files this one finds beyond what is already indexed are
|
||||
// exactly the ones the widen owes.
|
||||
for path in self.widened_files(added, &mut |w| warnings.push(w)) {
|
||||
let mut stats = 0usize;
|
||||
for found in self.widened_files(added, &mut |w| warnings.push(w), &mut trace) {
|
||||
let path = found.path.clone();
|
||||
// Already indexed: by another scope directory this walk overlaps,
|
||||
// or by an earlier scan. Re-reading it is the cost this path
|
||||
// exists to avoid.
|
||||
if held.contains(&path) {
|
||||
continue;
|
||||
}
|
||||
if let Some(size) = oversize(&path, cap) {
|
||||
if let Some(size) = oversize(&found, cap, &mut stats) {
|
||||
watch(IndexEvent::Skipped { path: &path, size, cap });
|
||||
skipped += 1;
|
||||
continue;
|
||||
@@ -1033,6 +1051,9 @@ impl Workspace {
|
||||
// buffer can widen — so the only warnings here are the walk's own.
|
||||
warnings,
|
||||
at: 0,
|
||||
// A widen names the directories it is about to walk, so there is
|
||||
// never anything left to discover.
|
||||
pending: None,
|
||||
staged: Vec::new(),
|
||||
staged_at: Vec::new(),
|
||||
words: HashMap::new(),
|
||||
@@ -1042,16 +1063,6 @@ impl Workspace {
|
||||
}
|
||||
}
|
||||
|
||||
/// The files the directories a widen added bring into scope, by the same
|
||||
/// rules [`Workspace::folder_files`] applies to the whole scope — including
|
||||
/// the rootless-at-depth-0 flat read.
|
||||
fn widened_files(&self, added: &[PathBuf], warn: &mut dyn FnMut(String)) -> Vec<PathBuf> {
|
||||
if self.roots.is_empty() && self.client.index_scope_depth == 0 {
|
||||
return sibling_files(added);
|
||||
}
|
||||
self.walked_files(added, warn)
|
||||
}
|
||||
|
||||
/// Index the next file of `scan`, reporting whether there was one.
|
||||
///
|
||||
/// One file is the whole step: **its text is read**, its record is taken —
|
||||
@@ -1075,7 +1086,7 @@ impl Workspace {
|
||||
pub fn scan_step(&mut self, scan: &mut Scan, watch: &mut dyn FnMut(IndexEvent)) -> bool {
|
||||
let (done, total) = (scan.at, scan.work.len());
|
||||
if done == total {
|
||||
return false;
|
||||
return self.discover_the_rest(scan, watch);
|
||||
}
|
||||
scan.at += 1;
|
||||
// The first file of a scan is the first thing to ask the store
|
||||
@@ -1479,7 +1490,7 @@ impl Workspace {
|
||||
// exists to skip.
|
||||
return (!doc.large).then(|| doc.text.clone());
|
||||
}
|
||||
if oversize(path, self.client.max_file_size).is_some() {
|
||||
if oversize(&Found::of(path), self.client.max_file_size, &mut 0).is_some() {
|
||||
return None;
|
||||
}
|
||||
fs::read_to_string(path).ok()
|
||||
@@ -1506,7 +1517,16 @@ impl Workspace {
|
||||
/// buffer is installed and the folder it raises to is known. What was
|
||||
/// already indexed is untouched; only the tail moves, and the finished
|
||||
/// index cannot tell ([`Scan::reorder`]).
|
||||
pub fn open_next(&self, scan: &mut Scan) {
|
||||
/// **The rest of the workspace is walked first when it has not been.** A
|
||||
/// split startup is leading with the folder the user *was* in; a `didOpen`
|
||||
/// says they are somewhere else now, and re-ordering a work list that does
|
||||
/// not yet contain the new folder would answer the request behind that
|
||||
/// `didOpen` off a prefix that cannot hold what it is asking about. The
|
||||
/// walk this order postpones is exactly what makes the new folder
|
||||
/// nameable, so it happens here
|
||||
/// (`docs/features/perf5r-first-answer/README.md`).
|
||||
pub fn open_next(&mut self, scan: &mut Scan, watch: &mut dyn FnMut(IndexEvent)) {
|
||||
self.discover_the_rest(scan, watch);
|
||||
let ordered = self.open_first(scan.remaining());
|
||||
scan.reorder(ordered);
|
||||
}
|
||||
@@ -1544,7 +1564,7 @@ impl Workspace {
|
||||
/// did when `collect_sources` read them all.
|
||||
pub fn sources(&self) -> Vec<(PathBuf, String)> {
|
||||
let Sources { files, mut buffered, .. } =
|
||||
self.collect_sources(&mut |_| {}, HeldAnalyses::Unused);
|
||||
self.collect_sources(&mut |_| {}, HeldAnalyses::Unused, &mut ScanTrace::new(false));
|
||||
files
|
||||
.into_iter()
|
||||
.filter_map(|path| {
|
||||
@@ -1866,78 +1886,6 @@ impl Workspace {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Resolve the scope: which files are in it, with open buffers overriding
|
||||
/// disk, and those buffers' own text.
|
||||
///
|
||||
/// **Metadata only, plus what is already in memory.** Nothing on disk is
|
||||
/// read here — a file's text is read by whoever indexes or rewrites it,
|
||||
/// one file at a time ([`Workspace::scan_step`], [`Workspace::sources`]).
|
||||
///
|
||||
/// This is where `lucisv.index.maxFileSize` applies, and it applies to the
|
||||
/// **walked** files only: an open buffer is folded in below whatever its
|
||||
/// size, because the user opened it deliberately and an editor that
|
||||
/// refused to understand the file on screen would be absurd. The check is
|
||||
/// a `metadata` call, so an oversized file is still never read at all —
|
||||
/// which is the whole saving, and it is still counted and reported here
|
||||
/// so that a scan's skip count is known before its first step.
|
||||
///
|
||||
/// A refactoring reads this same list through `sources()`, so a file the
|
||||
/// cap keeps out of the index is also a file a workspace rename will not
|
||||
/// rewrite. That is the consistent answer: the cap says which files exist
|
||||
/// as far as this server is concerned.
|
||||
fn collect_sources(
|
||||
&self,
|
||||
watch: &mut dyn FnMut(IndexEvent),
|
||||
analyses: HeldAnalyses,
|
||||
) -> Sources {
|
||||
let scope = self.source_files();
|
||||
let cap = self.client.max_file_size;
|
||||
// Every path an open buffer speaks for. Reading such a file from disk
|
||||
// is work thrown away — the buffer's text replaces it below, whatever
|
||||
// the disk says — so the read is skipped rather than undone. The cap is
|
||||
// still consulted first, so an oversized file still reports itself
|
||||
// skipped exactly as it did before the buffer put its own text back.
|
||||
let spoken_for: HashSet<&Path> =
|
||||
self.docs.values().filter_map(|doc| doc.path.as_deref()).collect();
|
||||
let mut files: Vec<PathBuf> = Vec::new();
|
||||
for path in scope.files {
|
||||
if let Some(size) = oversize(&path, cap) {
|
||||
watch(IndexEvent::Skipped { path: &path, size, cap });
|
||||
continue;
|
||||
}
|
||||
if spoken_for.contains(path.as_path()) {
|
||||
continue;
|
||||
}
|
||||
files.push(path);
|
||||
}
|
||||
// Open buffers override what is on disk, and contribute themselves
|
||||
// when they are not on disk at all.
|
||||
//
|
||||
// Except a buffer on the large-file fast path, which overrides disk
|
||||
// with *nothing*: indexing it means parsing the hundred megabytes the
|
||||
// fast path exists not to parse. Removing the path rather than leaving
|
||||
// the disk copy in is the honest half of that — the alternative would
|
||||
// be an index describing a file the user is looking at by bytes it no
|
||||
// longer has. See `docs/features/large-file-mode/README.md` for the
|
||||
// interaction with `lucisv.index.maxFileSize`, whose "an open buffer is
|
||||
// never capped" rule this is the one exception to.
|
||||
let mut analyzed = Analyzed::default();
|
||||
let mut buffered: HashMap<PathBuf, String> = HashMap::new();
|
||||
for doc in self.docs.values() {
|
||||
let Some(path) = doc.path.clone() else { continue };
|
||||
files.retain(|p| p != &path);
|
||||
if !doc.large {
|
||||
if analyses == HeldAnalyses::Wanted {
|
||||
analyzed.facts.insert(path.clone(), doc.facts(path.clone()));
|
||||
analyzed.words.insert(path.clone(), doc.words());
|
||||
}
|
||||
buffered.insert(path.clone(), doc.text.clone());
|
||||
files.push(path);
|
||||
}
|
||||
}
|
||||
Sources { files, buffered, analyzed, incdirs: scope.incdirs, warnings: scope.warnings }
|
||||
}
|
||||
|
||||
/// One **closed** file's text and line index, read at most once per file
|
||||
/// per generation of that file.
|
||||
///
|
||||
@@ -2020,155 +1968,6 @@ impl Workspace {
|
||||
None => fs::read_to_string(path).ok(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The files the index covers, and what the user should be told about how
|
||||
/// they were chosen. The scope ladder, highest first:
|
||||
///
|
||||
/// 1. **A filelist** — `lucisv.filelist`, else a `filelist` key in the
|
||||
/// config governing a workspace root. It names *exactly* the files to
|
||||
/// index; the project said so, and guessing past it would defeat the
|
||||
/// point of having one. This is the "project file", and it is the one
|
||||
/// rung that is whole-project by definition.
|
||||
/// 2. **The workspace-folder walk**, on `lucisv.index.scope:
|
||||
/// "workspace"` — what every session did before 2026-08-27, now opt-in.
|
||||
/// 3. **The folder scope**, the default: each opened buffer's own
|
||||
/// directory raised `lucisv.index.scopeDepth` levels, walked. See
|
||||
/// `docs/features/index-scope/README.md` for what that costs, which is
|
||||
/// that a definition in another folder does not resolve until the
|
||||
/// scope reaches that folder.
|
||||
///
|
||||
/// A configured filelist that cannot be read falls back to rung 2 (or 3)
|
||||
/// with a warning. An editor that shows no symbols because of a typo in a
|
||||
/// path is worse than one that quietly indexes what it can and says so.
|
||||
///
|
||||
/// Only rung 1 can carry `+incdir+` directories: a walked workspace names
|
||||
/// none, so an `` `include`` there resolves against the including file's
|
||||
/// own directory alone (`docs/features/include-nav/README.md`).
|
||||
fn source_files(&self) -> Scope {
|
||||
// The walk's own warnings join the scope's, so an unreadable directory
|
||||
// reaches the output channel by the road a filelist's problems already
|
||||
// travel — said once per scan and never per keystroke.
|
||||
let mut warnings: Vec<String> = Vec::new();
|
||||
let Some(path) = self.filelist_path() else {
|
||||
let files = self.default_files(&mut |w| warnings.push(w));
|
||||
return Scope { files, warnings, ..Default::default() };
|
||||
};
|
||||
match lucisv_core::filelist::read(&path) {
|
||||
Ok(list) => Scope { files: list.files, incdirs: list.incdirs, warnings: list.warnings },
|
||||
Err(problem) => {
|
||||
let files = self.default_files(&mut |w| warnings.push(w));
|
||||
warnings.insert(0, format!("{problem} — indexing the workspace instead"));
|
||||
Scope { files, incdirs: Vec::new(), warnings }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The filelist governing this workspace, if any: the client's setting
|
||||
/// first (absolute, or relative to the first root), else the `filelist`
|
||||
/// key of the config governing a root, in root order.
|
||||
///
|
||||
/// Public because the file watchers must name it: a `.f` edited outside
|
||||
/// the editor changes the index's scope, and nothing else on disk would
|
||||
/// tell us (`docs/features/file-watching/README.md`).
|
||||
pub fn filelist_path(&self) -> Option<PathBuf> {
|
||||
if let Some(setting) = &self.client.filelist {
|
||||
let path = Path::new(setting);
|
||||
return Some(match self.roots.first() {
|
||||
Some(root) if path.is_relative() => root.join(path),
|
||||
_ => path.to_path_buf(),
|
||||
});
|
||||
}
|
||||
let mut discovery = Discovery::new(true);
|
||||
// A broken `lucisv.toml` names no filelist, exactly as it contributes no
|
||||
// excludes below: the user hears about it when they format.
|
||||
self.roots.iter().find_map(|root| discovery.for_dir(root).ok()?.filelist)
|
||||
}
|
||||
|
||||
/// Rungs 2 and 3 of the ladder: the whole-workspace walk when the client
|
||||
/// asked for it, else the folder scope.
|
||||
fn default_files(&self, warn: &mut dyn FnMut(String)) -> Vec<PathBuf> {
|
||||
if self.walks_the_workspace() {
|
||||
return self.walked_files(&self.roots, warn);
|
||||
}
|
||||
self.folder_files(warn)
|
||||
}
|
||||
|
||||
/// Rung 3: the folder scope — [`Workspace::scope_dirs`], walked with every
|
||||
/// filter the workspace walk applies.
|
||||
///
|
||||
/// One exception, kept exactly as it was from before this rung became the
|
||||
/// default: **a rootless session at depth 0 reads its directories flat**,
|
||||
/// one level, no `.gitignore`. That is the "a file opened on its own"
|
||||
/// case, where descending a tree the user never named would be a surprise
|
||||
/// — and the moment the user raises `scopeDepth` they have named one, so
|
||||
/// the walk is what they asked for.
|
||||
fn folder_files(&self, warn: &mut dyn FnMut(String)) -> Vec<PathBuf> {
|
||||
let dirs = self.scope_dirs();
|
||||
if self.roots.is_empty() && self.client.index_scope_depth == 0 {
|
||||
return sibling_files(&dirs);
|
||||
}
|
||||
self.walked_files(&dirs, warn)
|
||||
}
|
||||
|
||||
/// Every source file under `dirs`, found by the CLI's own walk: the same
|
||||
/// extensions, the same `.gitignore` handling, and the `exclude` patterns
|
||||
/// of the config governing each directory. What `lucisv` skips, the index
|
||||
/// skips.
|
||||
///
|
||||
/// `dirs` is the workspace roots for rung 2 and the scope directories for
|
||||
/// rung 3. The one honest difference between the two: `.gitignore` files
|
||||
/// are read from the walk's own starting directory downwards, so a rule
|
||||
/// written in a root's `.gitignore` does not apply to a rung-3 walk that
|
||||
/// starts below it. The `exclude` patterns are matched against whole
|
||||
/// paths and so behave identically either way.
|
||||
fn walked_files(&self, dirs: &[PathBuf], warn: &mut dyn FnMut(String)) -> Vec<PathBuf> {
|
||||
let mut discovery = Discovery::new(true);
|
||||
let mut out = Vec::new();
|
||||
for root in dirs {
|
||||
// The walk names its inputs as strings; every directory here came
|
||||
// from a `file:` URI, which cannot carry a non-UTF-8 path.
|
||||
let Some(input) = root.to_str() else { continue };
|
||||
// A broken `lucisv.toml` must not stop the server from indexing: an
|
||||
// index that excludes nothing is a far better failure than a
|
||||
// server that comes up empty. The error is reported when the user
|
||||
// formats a file in this tree (`format::settings_for`).
|
||||
let mut exclude =
|
||||
discovery.for_dir(root).unwrap_or_default().exclude.unwrap_or_default();
|
||||
// The client's `lucisv.exclude` is *appended*, never substituted —
|
||||
// the CLI appends a config's excludes to `--exclude` the same way,
|
||||
// and a setting that silently dropped a checked-in exclude would
|
||||
// put vendored code back in the index for one user only.
|
||||
exclude.extend(self.client.exclude.iter().cloned());
|
||||
// `.gitignore` is always honoured: it is the CLI's default, and an
|
||||
// editor has no `--no-gitignore` to type. An unreadable directory
|
||||
// is skipped and said — the warning rides out on the scope's own
|
||||
// warnings, which `server/notification.rs` logs once per scan.
|
||||
let _ = collect_files(input, &exclude, true, &mut out, &mut |w| warn(w.to_string()));
|
||||
}
|
||||
out.sort();
|
||||
out.dedup();
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// The source files sitting in each of `dirs`, one directory deep. No walk, no
|
||||
/// `.gitignore`: this is the rootless default, where descending a tree the
|
||||
/// user never named would be a surprise.
|
||||
fn sibling_files(dirs: &[PathBuf]) -> Vec<PathBuf> {
|
||||
let mut out = Vec::new();
|
||||
for dir in dirs {
|
||||
let Ok(entries) = fs::read_dir(dir) else { continue };
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
let extension = path.extension().and_then(|e| e.to_str()).unwrap_or_default();
|
||||
if path.is_file() && EXTENSIONS.contains(&extension) {
|
||||
out.push(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
out.sort();
|
||||
out.dedup();
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -2807,7 +2606,7 @@ mod tests {
|
||||
let jumped = uri(&format!("file://{}", tree.path.join("c.sv").display()));
|
||||
let jumped_text = fs::read_to_string(tree.path.join("c.sv")).expect("the fixture");
|
||||
stepped.set_document(jumped, jumped_text);
|
||||
stepped.open_next(&mut scan);
|
||||
stepped.open_next(&mut scan, &mut |_| {});
|
||||
assert!(stepped.scan_step(&mut scan, &mut |_| {}));
|
||||
stepped.publish_scan(&mut scan);
|
||||
assert!(!stepped.index().units("c").is_empty(), "c.sv was indexed next, not last");
|
||||
@@ -2940,7 +2739,7 @@ mod tests {
|
||||
ws.open_whole_workspace(vec![tree.path.clone()]);
|
||||
assert_eq!(indexed(&ws, &["a", "b"]), ["a", "b"]);
|
||||
assert_eq!(
|
||||
ws.walked_files(from_ref(&tree.path), &mut |_| {}).len(),
|
||||
ws.walked_files(from_ref(&tree.path), &mut |_| {}, &mut ScanTrace::new(false)).len(),
|
||||
2,
|
||||
"two files, once each"
|
||||
);
|
||||
@@ -4224,7 +4023,7 @@ mod tests {
|
||||
let mut scan = ws.begin_scan(&mut |_| {}, false);
|
||||
assert!(ws.scan_step(&mut scan, &mut |_| {}), "the buffer's own file goes first");
|
||||
open(&mut ws, &tree, "ip/uart/rtl/uart.sv");
|
||||
ws.open_next(&mut scan);
|
||||
ws.open_next(&mut scan, &mut |_| {});
|
||||
// `uart.sv` is now the head of what is left, and at the shipped
|
||||
// `scopeDepth: 2` its own folder raises to `ip` — which brings
|
||||
// `ip/kmac` in with it. Four files of waiting, one behind the file
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//! `pub(super)` and visible exactly where they were before the move: inside
|
||||
//! `crate::state` and nowhere else.
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
@@ -126,6 +126,11 @@ pub struct Scan {
|
||||
pub(super) warnings: Vec<String>,
|
||||
/// How many of `work` have been indexed.
|
||||
pub(super) at: usize,
|
||||
/// The rest of the workspace, still to be discovered — see
|
||||
/// [`PendingDiscovery`]. `None` for every scan that resolved its whole
|
||||
/// scope before it started, which is every scan but a workspace-scoped
|
||||
/// startup with a buffer already open.
|
||||
pub(super) pending: Option<PendingDiscovery>,
|
||||
/// The records taken since the last publish, and which files of `work`
|
||||
/// they came from. Staged rather than merged because a merge is a pass
|
||||
/// over the whole index — see [`vlog_semantic::WorkspaceIndex::absorb`].
|
||||
@@ -144,6 +149,27 @@ pub struct Scan {
|
||||
pub(super) trace: ScanTrace,
|
||||
}
|
||||
|
||||
/// The half of a scan's scope that has not been walked yet.
|
||||
///
|
||||
/// **One scan, discovered in two goes.** A workspace-scoped session with a
|
||||
/// buffer already open walks that buffer's own folders first, indexes them,
|
||||
/// publishes them and answers the request that has been waiting — and only
|
||||
/// then walks the remaining 3 800 directories, whose 155 ms used to sit in
|
||||
/// front of every one of those steps (`docs/features/perf5r-first-answer`).
|
||||
/// It is emphatically **not** two scans: one work list, one index, one
|
||||
/// `finish_scan`, one `gone` computed against the whole of it, and every file
|
||||
/// stepped exactly once — which is what `seen` is for.
|
||||
pub(super) struct PendingDiscovery {
|
||||
/// The directories still to walk: the workspace roots.
|
||||
pub(super) roots: Vec<PathBuf>,
|
||||
/// Every path the neighbourhood walk yielded — the ones it indexed, the
|
||||
/// ones the size cap kept out, and every open buffer's own path. The
|
||||
/// remaining walk covers the roots, so it finds all of these again; each
|
||||
/// one it names here has already been decided about, and deciding twice
|
||||
/// would step a file twice or report one skip as two.
|
||||
pub(super) seen: HashSet<PathBuf>,
|
||||
}
|
||||
|
||||
/// Which of the two shapes a [`Scan`] is.
|
||||
///
|
||||
/// One enum rather than two `finish` methods so a caller cannot pair the wrong
|
||||
@@ -195,6 +221,44 @@ impl Scan {
|
||||
self.at >= self.head
|
||||
}
|
||||
|
||||
/// Whether this scan still owes itself the rest of its own scope — see
|
||||
/// [`PendingDiscovery`].
|
||||
///
|
||||
/// Two callers, and they want it for the same reason: `scan_once` must
|
||||
/// interleave a scan whose work list is short *so far*, and must not paint
|
||||
/// a percentage against a denominator that is going to grow
|
||||
/// (`docs/features/indexing-ux/README.md`).
|
||||
pub fn discovery_pending(&self) -> bool {
|
||||
self.pending.is_some()
|
||||
}
|
||||
|
||||
/// Take the remaining discovery, so the workspace can run it.
|
||||
pub(super) fn take_pending(&mut self) -> Option<PendingDiscovery> {
|
||||
self.pending.take()
|
||||
}
|
||||
|
||||
/// Fold the rest of the scope into this scan: its files onto the end of
|
||||
/// the work list, its paths into the set the include graph learns from,
|
||||
/// its warnings and its skips onto the scan's own.
|
||||
///
|
||||
/// Appended rather than re-ordered: the neighbourhood at the front has
|
||||
/// already been stepped, and `vlog_semantic::IndexBuilder` sorts by path
|
||||
/// inside `finish`, so what arrives here decides latency and nothing else
|
||||
/// ([`Scan::reorder`] makes the same argument).
|
||||
pub(super) fn land_discovery(
|
||||
&mut self,
|
||||
files: Vec<PathBuf>,
|
||||
warnings: Vec<String>,
|
||||
skipped: usize,
|
||||
) {
|
||||
self.paths.extend(files.iter().cloned());
|
||||
self.paths.sort();
|
||||
self.paths.dedup();
|
||||
self.work.extend(files);
|
||||
self.warnings.extend(warnings);
|
||||
self.skipped += skipped;
|
||||
}
|
||||
|
||||
/// The text of one file of this scan's work list, at the moment its step
|
||||
/// comes — `None` when it cannot be read.
|
||||
///
|
||||
|
||||
@@ -81,6 +81,11 @@ parser** a push does, so the two paths cannot drift.
|
||||
describes only an answer that arrives after the 2 s bound
|
||||
(`CONFIGURATION_WAIT`), which is then an ordinary settings change with an
|
||||
ordinary rescan behind it.
|
||||
**2026-09-08 (perf5r-first-answer):** and the staging window now also
|
||||
holds `OPENING_FILE_WAIT` (25 ms) for the editor's opening `didOpen`, so a
|
||||
buffer that arrives just after the configuration answer still orders the
|
||||
first scan around its folder; a session whose opening burst already holds
|
||||
a `didOpen` spends none of it.
|
||||
**2026-08-27:** `lucisv.index.maxFileSize` joins those two — a pulled cap
|
||||
that differs from the 1 MiB default costs the same one extra rescan — and
|
||||
`lucisv.index.logFiles` shows the other face of the same fact: the startup
|
||||
|
||||
@@ -642,6 +642,43 @@ is read either way, so an mtime match could only ever have saved this.
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-09-08 — §61.3: the store open, split into its parts (measured, unchanged)
|
||||
|
||||
**Nothing in this feature changed.** With §61.3 putting the workspace walk
|
||||
*behind* the first useful answer, `IndexCache::open` became the largest thing
|
||||
left in front of it — 89 ms of a 115 ms warm answer — so the review's "measure
|
||||
a bounded local-record loading design before proposing a format change" clause
|
||||
came live. It was measured, against the real 46 486 433-byte OpenTitan store
|
||||
(3 977 records, page-cached), with a throwaway instrumented build:
|
||||
|
||||
| part of `IndexCache::open` | ms |
|
||||
|---|---:|
|
||||
| `read` — the whole 46.5 MB | **6.31** |
|
||||
| line split into 3 977 slices | **14.93** |
|
||||
| extracting every line's path field (no checksum, no allocation) | **2.27** |
|
||||
| **verifying every record's checksum** (FNV-1a over ~45 MB) | **60.99** |
|
||||
|
||||
**73 % of the open is verifying records the answer will never look at.** A
|
||||
bounded local load — paths first, then decode only the neighbourhood's ~124
|
||||
records — costs about **26 ms** and would take the warm first answer to roughly
|
||||
50. It is bounded, and it needs **no format change**.
|
||||
|
||||
It was **not implemented**, and the reason is this README's own accounting. The
|
||||
61 ms is owed either way: the other 3 852 records must be verified before the
|
||||
scan can hit them, so lazy verification moves cost rather than removing it. What
|
||||
it *changes* is [`Load::canonical`](#the-store-format) — `dropped` counts the
|
||||
records the checksum rejects, and a load that has not verified them cannot say
|
||||
whether the file it holds is the file `compact` would write. That single flag
|
||||
is what §P4b's compaction skip rests on, and what makes "the store is
|
||||
byte-identical across warm sessions" true (28 stores, three hashes, both
|
||||
binaries, §61.3). It also changes an answer in the attack matrix below: under
|
||||
lazy verification a **corrupt later line for a path would displace a good
|
||||
earlier one** instead of being dropped at load, so
|
||||
`a_corrupt_record_is_dropped_and_the_rest_of_the_store_is_not` would need
|
||||
re-attacking rather than re-running. That is an experiment with its own QA, not
|
||||
a rider on a latency lane. Filed with these numbers in
|
||||
`docs/features/perf5r-first-answer/README.md`.
|
||||
|
||||
### 2026-08-27 — dev agent (a persistent index cache with crash/reopen resume)
|
||||
|
||||
- **The key is the content and only the content, and that is the round's one
|
||||
|
||||
@@ -606,6 +606,44 @@ and it is where the measured cost was.
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-09-08 — §61.3: the workspace rung is discovered in two goes
|
||||
|
||||
**The scope is unchanged; when it is resolved is not.** A rung-2 session with a
|
||||
buffer already open now walks the folders that buffer raises to **first**,
|
||||
indexes and publishes them, and walks the rest of the workspace afterwards —
|
||||
one scan, one work list, every file stepped once, `gone` computed against the
|
||||
whole of it (`docs/features/perf5r-first-answer/README.md`). The first useful
|
||||
definition went from 301 ms warm / 266 cold to **115 / 78**.
|
||||
|
||||
Three things in this README's territory, and all three are "the same rule,
|
||||
asked earlier":
|
||||
|
||||
- **The rung is unchanged.** The split is taken only when rung 2 is in force,
|
||||
so a filelist and the folder rung resolve exactly as they did. `scopes`, eight
|
||||
requests × three scopes × both binaries: 24 of 24 result counts equal, and
|
||||
the persistent store is byte-identical.
|
||||
- **The head obeys the root's rules.** A walk starting at `hw/ip/aes` reads no
|
||||
`.gitignore` above itself, and this README's own note — "a rule written in a
|
||||
root's `.gitignore` does not apply to a rung-3 walk that starts below it" —
|
||||
is a statement about *rung 3*, where the folder **is** the scope. Under
|
||||
rung 2 the root is the scope, so the folder half of one scan must obey the
|
||||
root's rules or the two halves disagree about which files exist.
|
||||
`lucisv_core::walk::collect_files_below` carries the ancestor ignore stack
|
||||
down and refuses an ancestor the root walk would not have entered;
|
||||
`the_split_head_obeys_a_gitignore_written_at_the_workspace_root` is the wire
|
||||
test.
|
||||
- **The bound is `worth_waiting`'s own, asked without the total.** A scan that
|
||||
has not walked the workspace cannot ask whether its head is a minority of it,
|
||||
so the split is refused unless every raised folder is a **strict** descendant
|
||||
of a workspace root — the case that rule exists for — and again if the walk
|
||||
finds more than 512 files there. Refused, the scan is byte-for-byte the one
|
||||
before this round.
|
||||
|
||||
The size cap now reads the length the walk already stat'd
|
||||
(`lucisv_core::walk::collect_files_with`): 3 979 `metadata` calls per scan
|
||||
became **0**, worth a measured 6.9 ms of a 165 ms discovery. A filelist entry
|
||||
is not walked and still stats once, exactly as before.
|
||||
|
||||
### 2026-09-08 — §P4b3: the read moment, and the order the walk is indexed in
|
||||
|
||||
**Two documented behaviours moved. The scope ladder itself — precedence, the
|
||||
|
||||
@@ -345,6 +345,34 @@ nine sizes, and a real 1100-file workspace end to end.
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-09-08 — §61.3: no report while the denominator can still grow
|
||||
|
||||
**Amends the denominator assumption, and keeps both of its properties.** A
|
||||
workspace-scoped startup with a buffer open now takes its work list in two
|
||||
goes — the user's own folder, then the rest of the workspace
|
||||
(`docs/features/perf5r-first-answer/README.md`) — so for the length of that
|
||||
head, "what this scan will do" is not yet known.
|
||||
|
||||
The rule this README states is *"the percentage only counts up, and every one
|
||||
of them is measured"*, and a growing denominator breaks both: 124/124 followed
|
||||
by 125/3 976 is a bar that falls from 100 % to 3 %. Neither of the review's two
|
||||
suggestions was taken — a second `$/progress` token would put two bars on one
|
||||
scan, and a "known so far" denominator is exactly the invented percentage
|
||||
`begin_indexing` refuses. What ships instead costs nothing: **the bar token is
|
||||
withheld while the work list can still grow**. `IndexWatch::tick` needs the
|
||||
token and returns early without one; `IndexWatch::say` does not, so **every
|
||||
file of the head is still named in the per-file log**. The client sees the
|
||||
`begin` (which has carried no percentage since it was written), then the log,
|
||||
then the first *measured* report — against the finished work list, counting up
|
||||
from there. The last file still always reports.
|
||||
|
||||
`the_bar_paints_no_percentage_until_the_denominator_is_final` asserts all
|
||||
three: the sequence never falls, the first report is not the head's own 50 %,
|
||||
and both the buffer's step and its folder's are in the log.
|
||||
|
||||
The skip count is unaffected: the head's skips and the rest's are summed onto
|
||||
the same scan, and the end message names the total as it always did.
|
||||
|
||||
### 2026-08-27 — dev agent (indexing UX: cap, counting bar, per-file log)
|
||||
|
||||
- **`vlog_semantic`: builder, not callback — and the reason is `FileId`.**
|
||||
|
||||
@@ -0,0 +1,833 @@
|
||||
# perf5r-first-answer — the first useful answer of a workspace start (R2a, R2b)
|
||||
|
||||
## Goal
|
||||
|
||||
A workspace-scoped session answered its first `textDocument/definition` in
|
||||
**301 ms warm / 266 ms cold** at 0.51.0, and the independent review
|
||||
([§2](../../performance_take5_review.md)) traced 91 % of it to two stages that
|
||||
run *before* the user's own folder is touched: **155–183 ms discovering the
|
||||
workspace** and **89 ms opening the persistent store**. §P4b3 had already made
|
||||
that answer correct (it used to be `[]`); what it could not do was make it
|
||||
fast, because one scan cannot step the folder the user is in until it knows
|
||||
which files exist.
|
||||
|
||||
This lane makes it stop having to. The scan now **walks the user's own folders
|
||||
first, indexes them, publishes them and answers the request waiting for them —
|
||||
and only then walks the rest of the workspace**. It is still one scan: one work
|
||||
list, one index, one `finish_scan`, one `gone` set computed against the whole
|
||||
of it, and every file stepped exactly once. Beside it, the size cap stops
|
||||
asking the filesystem for a number the walk already had. Measured, paired
|
||||
against §61.2's trunk over OpenTitan's 3 976 files: first useful definition
|
||||
**266 → 78 ms cold (−70.7 %)** and **301 → 115 ms warm (−61.8 %)** — re-taken
|
||||
on the final build as **265 → 81** and **278 → 114** — result count 1 in every
|
||||
session of both, with the warm quiet settle at **997 ms** and idle RSS **8.6 %
|
||||
lower cold**.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **Ordering cannot change what the index holds.** `vlog_semantic::IndexBuilder`
|
||||
sorts its records by path inside `finish`, so which order a scan takes files
|
||||
in decides latency and reporting and nothing else. Every claim below rests on
|
||||
that, and the store's byte-for-byte identity across both binaries is the
|
||||
measurement that checks it.
|
||||
- **The user's own folder is a small part of their workspace.** OpenTitan's
|
||||
`hw/ip/aes` is 124 files of 3 976. Where that is not true the split is
|
||||
refused rather than assumed: see [`HEAD_WALK_MAX`](#the-three-bounds) and the
|
||||
root-level buffer rung below.
|
||||
- **A walk that starts below a root must obey that root's rules.** A
|
||||
`.gitignore` at the workspace root governs the whole rung-2 scope, and a walk
|
||||
beginning at `hw/ip/aes` would never read it. `lucisv_core::walk::collect_files_below`
|
||||
is the assumption made into code; without it the two halves of one scan would
|
||||
disagree about which files exist.
|
||||
- **A `metadata` call is cheap when the inode is already hot.** The cap's second
|
||||
`stat` per file measured **6.9 ms of a 165 ms discovery**, not the ~45 ms the
|
||||
§P4b3 note guessed at. The hand-off is still right — 3 976 system calls for a
|
||||
number already in hand — but it is a tidy-up, not the lever.
|
||||
- **The editor names its open file in the same breath as its settings.** Which
|
||||
of the two arrives first is a race between two of the client's own threads
|
||||
(`workspace/configuration` is answered by whatever handles server-initiated
|
||||
requests; the `didOpen` comes from the editor). Losing it cost the whole
|
||||
win — 6 sessions of 8 split, 2 paid the old 290 ms — so the staging window now
|
||||
waits a bounded 25 ms for the file name. That bound is spent only by a
|
||||
workspace-scoped session with an empty editor, where nothing is waiting on
|
||||
the scan.
|
||||
- **A request held for the startup scan is answered when the user's folder is
|
||||
published, even when its target is elsewhere.** That is today's rule, not a
|
||||
new one, and it is pinned rather than changed — see
|
||||
[the cross-folder target](#the-cross-folder-target).
|
||||
|
||||
## Handshakes
|
||||
|
||||
### `lucisv_core::walk` — two additive entries
|
||||
|
||||
Both are **additive**: `collect_files` keeps its signature, its order, its
|
||||
warnings and its behaviour, and is now a two-line wrapper. The 102 existing
|
||||
`lucisv_core` tests all pass unchanged; 7 were added.
|
||||
|
||||
```rust
|
||||
/// `collect_files` with the size the walk already read handed on beside
|
||||
/// each path. `None` = the walk did not stat this one (an input named
|
||||
/// rather than walked); every path a directory walk yields carries `Some`.
|
||||
pub fn collect_files_with(
|
||||
input: &str,
|
||||
exclude: &[String],
|
||||
gitignore: bool,
|
||||
found: &mut dyn FnMut(PathBuf, Option<u64>),
|
||||
warn: &mut dyn FnMut(Warning),
|
||||
) -> Result<(), String>;
|
||||
|
||||
/// `collect_files_with` over `input`, which lies **under** `root`, finding
|
||||
/// exactly what a walk of `root` would have found there: the ancestors'
|
||||
/// `.gitignore` rules are read onto the stack at the depth they belong at,
|
||||
/// and an ancestor the root walk would not have entered yields nothing.
|
||||
pub fn collect_files_below(
|
||||
root: &Path,
|
||||
input: &Path,
|
||||
exclude: &[String],
|
||||
gitignore: bool,
|
||||
found: &mut dyn FnMut(PathBuf, Option<u64>),
|
||||
warn: &mut dyn FnMut(Warning),
|
||||
) -> Result<(), String>;
|
||||
```
|
||||
|
||||
`Walk` holds `found: &mut dyn FnMut(PathBuf, Option<u64>)` where it held
|
||||
`files: &mut Vec<PathBuf>`. The length comes off the `metadata` call the walk
|
||||
*already makes* on every directory entry to answer "directory?" — so the walk
|
||||
costs nothing more, and the server's cap costs one `stat` per file less.
|
||||
|
||||
**What this promises:** the two entries and `collect_files` find the same
|
||||
files in the same order under the same filters. Pinned by
|
||||
`the_metadata_entry_yields_exactly_the_paths_the_plain_one_does` and, for the
|
||||
below-walk, by `a_walk_that_starts_below_a_root_still_obeys_that_roots_gitignore`
|
||||
and `a_negation_below_the_root_still_wins_over_the_root_rule`, both of which
|
||||
assert equality with the whole-root walk restricted to that subtree.
|
||||
|
||||
### `lucisv_server` internals
|
||||
|
||||
- **`crate::state::discover`** is a new child module of `crate::state`: `Found`,
|
||||
`Scope`, `oversize`, `collect_sources`, `overlay_buffers`, `source_files`,
|
||||
`filelist_path`, `walked_files`, `widened_files`, `sibling_files` moved there
|
||||
from `state/mod.rs` (a move; `state/mod.rs` is 1 069 → **978** production
|
||||
lines), and `first_scope`, `splits_discovery`, `leads_with_a_folder`,
|
||||
`neighbourhood_files`, `rest_of_scope` are new there.
|
||||
- `Workspace::collect_sources`, `source_files`, `walked_files`, `widened_files`
|
||||
take `&mut ScanTrace` (the stage split). Test callers pass
|
||||
`&mut ScanTrace::new(false)`, which allocates nothing and records nothing.
|
||||
- `Workspace::open_next` becomes `&mut self` and takes a
|
||||
`watch: &mut dyn FnMut(IndexEvent)`: a `didOpen` answered mid-scan finishes
|
||||
any pending discovery before re-ordering, and the skips that discovery
|
||||
reports need somewhere to go.
|
||||
- `Scan` gains `pending: Option<PendingDiscovery>` and the three methods over
|
||||
it (`discovery_pending`, `take_pending`, `land_discovery`). `Scan::total()`
|
||||
is now "how many files this scan has taken *so far*" while discovery is
|
||||
pending — `server/index.rs` is the only reader and says so.
|
||||
- `ScanTrace` gains `config_ms`, `walk_ms`, `walk_dirs`, `filelist_ms`,
|
||||
`sort_ms`, `cap_ms`, `stats`, `buffers_ms` — a **split of** `discovery_ms`,
|
||||
not stages beside it. The stage line gains `config= walk= filelist= sort=
|
||||
cap= buffers=`; the count line gains `walk_dirs=` and `stats=`. Both are
|
||||
`key=value`, so `tools/perf/phases_p4.py` reads them with no change.
|
||||
- `Server` gains `OPENING_FILE_WAIT` and `Server::await_opening_file`, inside
|
||||
the existing staging window.
|
||||
|
||||
### Amendments to other features' READMEs (dated entries, rules unchanged)
|
||||
|
||||
- `docs/features/index-scope/README.md` — the workspace rung is discovered in
|
||||
two goes when a buffer is open; the scope it resolves to is unchanged.
|
||||
- `docs/features/scan-interleave/README.md` — a scan with a pending discovery
|
||||
always interleaves, whatever its work list says so far.
|
||||
- `docs/features/indexing-ux/README.md` — no progress *report* while the
|
||||
denominator can still grow; the per-file log is unchanged. This keeps the
|
||||
README's own "the percentage only counts up, and every one is measured".
|
||||
- `docs/features/index-persistence/README.md` — the measured split of the 89 ms
|
||||
store open, and why a bounded local load was measured and not shipped.
|
||||
|
||||
### Requests for the lead (`docs/topo.md` is not edited by this lane)
|
||||
|
||||
1. `lucisv_server ──▶ lucisv_core` (walk): **`collect_files_with` and
|
||||
`collect_files_below`**, both additive, `collect_files` unchanged and now a
|
||||
wrapper. The server's cap reads the walk's own `metadata`; its
|
||||
neighbourhood walk starts below a root and carries that root's `.gitignore`
|
||||
rules down. Nothing else in the tree calls either (the CLI still calls
|
||||
`collect_files`).
|
||||
2. A new server module `crate::state::discover`, consumed by
|
||||
`crate::state::mod` alone. Mostly a move out of `state/mod.rs`.
|
||||
3. `Scan::pending` / `PendingDiscovery`, `Workspace::open_next`'s new
|
||||
signature, and `ScanTrace`'s eight new fields — all internal to
|
||||
`lucisv_server`, all additive.
|
||||
4. `server/startup.rs` gains `OPENING_FILE_WAIT` (25 ms) inside the staging
|
||||
window. **This amends `docs/features/folders-and-config/README.md`'s
|
||||
Assumptions again** — the pull's timing sentence — and that README is not
|
||||
this lane's file: a request, not an edit.
|
||||
5. **Not made, filed:** a held startup request whose target the published
|
||||
prefix cannot resolve should wait rather than answer `[]`. That is a
|
||||
`server/dispatch.rs` decision (the answer has to be computed to know), and
|
||||
`server/dispatch.rs` is not this lane's file. See
|
||||
[the cross-folder target](#the-cross-folder-target).
|
||||
6. **Not made, filed:** `IndexCache::open`'s 61 ms of checksum verification is
|
||||
deferrable per record, which would take the warm first answer from ~115 ms
|
||||
to ~50. It is bounded and needs no format change, but it moves the one
|
||||
accounting the compaction skip and the byte-identical-store gate rest on
|
||||
(`Load::canonical`). Measured below; recommended as its own experiment with
|
||||
its own persistence attacks, not smuggled into this one.
|
||||
|
||||
## How it works
|
||||
|
||||
### Two-phase discovery, one scan
|
||||
|
||||
`Workspace::begin_scan` asks `first_scope` for its scope. When
|
||||
`splits_discovery()` says yes it gets **the neighbourhood only**, plus a
|
||||
`PendingDiscovery` naming the roots still to walk and every path the
|
||||
neighbourhood already decided about. The work list is the open buffers and
|
||||
their folders; `head` is all of it.
|
||||
|
||||
`scan_step`, on reaching the end of that list, runs `discover_the_rest`:
|
||||
`rest_of_scope` walks the roots, drops everything `seen` already named, applies
|
||||
the cap, and `Scan::land_discovery` appends the result to `work` and folds it
|
||||
into `paths`, the warnings and the skip count. **It indexes nothing and returns
|
||||
`true`**, so the next step is an ordinary one — which is what keeps the
|
||||
progress denominator from growing inside a step that is reporting against it.
|
||||
|
||||
`server/index.rs`'s loop is unchanged in shape. What it added:
|
||||
|
||||
- `interleave` is `total > INTERLEAVE_ABOVE` **or** `scan.discovery_pending()`,
|
||||
because a head of 124 files is under the threshold and the request waiting
|
||||
for it must still be answered inside the scan;
|
||||
- the bar token is withheld while `discovery_pending()`, so no percentage is
|
||||
painted against a denominator about to grow twentyfold. `IndexWatch` still
|
||||
logs every file — `tick` needs the token, `say` does not;
|
||||
- a burst carrying a `didOpen` now calls `open_next` through `watching`, and
|
||||
`open_next` finishes any pending discovery before re-ordering: the user has
|
||||
jumped somewhere the walk has not reached, and re-ordering a list that
|
||||
cannot contain the new folder would answer the request behind it off a
|
||||
prefix that cannot hold its target.
|
||||
|
||||
`head_owed`, `worth_waiting`, `waiting_for_this_scan` and the coalescing rule
|
||||
are untouched.
|
||||
|
||||
### The three bounds
|
||||
|
||||
None of them is new policy: the first two are `scan_order::worth_waiting`'s own
|
||||
rule asked in a form that does not need the total, and the third is
|
||||
`must_wait`'s.
|
||||
|
||||
1. **`splits_discovery`** requires the workspace walk to be the rung in force
|
||||
*and* every raised folder to be a **strict** descendant of a workspace root.
|
||||
A buffer opened from the root raises to the root, and its "folder" is the
|
||||
whole scan — exactly the case `worth_waiting` returns 0 for. Refused, the
|
||||
scan is byte-for-byte the one this round started from.
|
||||
2. **The session's first scan only.** Every later whole rescan is one a
|
||||
message asked for, and `must_wait`'s `answering_a_rescan` holds every
|
||||
request for the whole of it — so leading with a folder buys no answer any
|
||||
sooner there and costs the neighbourhood one extra directory traversal. The
|
||||
startup scan is the one with nothing queued ahead of it, and it is the one
|
||||
this order is for. `a_rescan_does_not_lead_with_a_folder_because_nothing_may_be_answered_inside_it`
|
||||
pins it.
|
||||
3. **`HEAD_WALK_MAX` = 512.** Past that many files the neighbourhood is not
|
||||
provably a minority of anything, so the walk is finished immediately, the
|
||||
two lists are merged in path order, and the scan is ordered exactly as
|
||||
before with `worth_waiting` deciding the drain. 512 is measured, not round:
|
||||
a warm step is ~0.2 ms a file (124 files in 25 ms, §P4b3), so a head this
|
||||
size is ~100 ms of stepping and the first answer still fits the round's
|
||||
200 ms gate.
|
||||
|
||||
### The cross-folder target
|
||||
|
||||
A held startup request is drained the moment the user's folder is published.
|
||||
When its target lives in **another** folder the answer is `[]` — the same
|
||||
answer a request arriving mid-scan has always had for a file the scan has not
|
||||
reached (`docs/features/scan-interleave/README.md`). The reference does the
|
||||
same thing one interleave point earlier, so the split neither introduces the
|
||||
case nor widens it, and
|
||||
`a_target_outside_the_head_is_answered_when_the_head_is_published_and_is_empty`
|
||||
pins both halves: `[]` at the head, and the right location once settled.
|
||||
|
||||
The review's gate — *every first-definition result equal to the settled
|
||||
target* — is met on the measured cursor and on every mid-scan request the
|
||||
`scanserve` probe sent (`unsettled_answers` **0** for both binaries, cold and
|
||||
warm). It is **not** met by construction for an arbitrary cursor, and saying so
|
||||
is the honest position: making it true needs the drain to know whether the
|
||||
published index already resolves *this request's* target, which means computing
|
||||
the answer and putting the request back when it is empty. That lives in
|
||||
`server/dispatch.rs` — filed as request 5 rather than done here. Its cost, for
|
||||
the lead's ruling: one extra evaluation per held request per interleave point,
|
||||
and a request whose answer is genuinely empty waits until the scan settles.
|
||||
|
||||
## Measured
|
||||
|
||||
Machine: M1 Max, macOS 27.0, release profile, `rustc 1.97.1 (Homebrew)`,
|
||||
`cargo build --release --locked` before every timing. OpenTitan
|
||||
`0098135264` with its three known pre-existing modified files;
|
||||
`git -C … status --porcelain` checked after every phase and never otherwise
|
||||
touched. Every session and every cargo command under
|
||||
`tools/guard.sh -m 8 -t 1800`; **no guard kill**. No cargo command ran during a
|
||||
timed phase. One-minute load recorded before and after each phase: **1.8–4.2**
|
||||
except the first `scanprofile` pair, which ran into a burst of `syspolicyd` /
|
||||
`mediaanalysisd` at load 8.6 and was **re-run** in the quiet window; both runs
|
||||
are quoted below. Rows: `~/.cache/lucisv-perf/take5r-3/results.jsonl`.
|
||||
|
||||
Binaries (sha256):
|
||||
|
||||
| label | what | sha256 |
|
||||
|---|---|---|
|
||||
| `REF` | trunk `a1c77c0` (§61.2 merged) | `827c7ac222c829d1…` |
|
||||
| `SPLIT` | `REF` + the discovery stage split, cap still stat'ing | `afc5bf04474dd8ab…` |
|
||||
| `R2A` | `SPLIT` + the walk metadata hand-off | `533a364dd18782db…` |
|
||||
| `R2` | `R2A` + the two-phase discovery and the opening-file bound | `3db0c799a8302696…` |
|
||||
| `R2f` | `R2` + the first-scan gate (the confirmation re-run) | `f7a5a27eec773eca…` |
|
||||
|
||||
### R2a — the discovery stage split, measured before anything moved
|
||||
|
||||
`SPLIT`, one traced session per cell (`scanwait`, `--verbose`), all values ms:
|
||||
|
||||
| stage | cold | warm | what it is |
|
||||
|---|---:|---:|---|
|
||||
| `discovery` | **186.59** | **165.56** | the whole of it |
|
||||
| `config` | 0.00 | 0.00 | `Discovery::for_dir` — `lucisv.toml` excludes, cached per instance |
|
||||
| `walk` | 178.21 | 158.01 | `read_dir`, `.gitignore`, the cycle guard, the walk's own `metadata` |
|
||||
| `filelist` | 0.00 | 0.00 | rung 1 is not in force here |
|
||||
| `sort` | 0.55 | 0.52 | path order + dedup over 3 976 |
|
||||
| `cap` | 7.53 | **6.92** | `lucisv.index.maxFileSize`, **3 979 `metadata` calls** |
|
||||
| `buffers` | 0.23 | 0.00 | the open buffer's text and analysis |
|
||||
|
||||
**The finding is the size of `cap`.** §P4b3 filed the second `stat` as the
|
||||
thing to remove; it is **6.9 ms of 165**, because the walk has just warmed
|
||||
every one of those inodes. `walk` is 95 % of discovery and nothing inside
|
||||
`lucisv_core` makes it cheaper — which is what sent this lane at the *order*
|
||||
rather than at the walk.
|
||||
|
||||
### R2a — the hand-off, paired against `SPLIT`
|
||||
|
||||
`R2A`, same phase, same window:
|
||||
|
||||
| | `SPLIT` | `R2A` | |
|
||||
|---|---:|---:|---|
|
||||
| `stats` (cap `metadata` calls), cold / warm | 3 979 / 3 979 | **0 / 0** | the walk's own number is used |
|
||||
| `cap` ms, cold / warm | 7.53 / 6.92 | **0.49 / 0.10** | −93 % / −99 % |
|
||||
| `discovery` ms, cold / warm | 186.59 / 165.56 | **179.95 / 154.90** | −3.6 % / −6.4 % |
|
||||
| first useful answer, cold (3 sessions) | 273.1 / 260.9 / 258.0 | 263.3 / 257.3 / 256.1 | −1.4 % on medians |
|
||||
| first useful answer, warm (3 sessions) | 281.3 / 300.8 / 282.8 | 271.1 / 294.8 / 290.9 | +2.9 %, inside the spread |
|
||||
|
||||
**Honest reading: the hand-off removes 3 976 system calls and about 7 ms, and
|
||||
the first answer does not move.** It is kept because 3 976 syscalls to learn a
|
||||
number already in hand is work with no defence, and because it costs nothing;
|
||||
it is not the reason the first answer got faster.
|
||||
|
||||
### R2b — the first useful answer, paired `REF` vs `R2`
|
||||
|
||||
Three fresh sessions per cell, medians, phases run `REF` then `R2` back to
|
||||
back. Every session returned **result count 1**.
|
||||
|
||||
| cell | `REF` | `R2` | paired |
|
||||
|---|---:|---:|---|
|
||||
| `scanwait`, cold — first useful definition | 272.1 / 265.9 / **265.1** | 83.9 / **77.9** / 77.2 | **−70.7 %** |
|
||||
| `scanwait`, warm — first useful definition | 300.6 / **301.3** / 303.4 | 113.4 / **115.1** / 115.5 | **−61.8 %** |
|
||||
| `scan`, cold — first useful definition | **261.3** / 260.7 / 262.7 | 78.8 / 83.2 / **81.5** | **−68.8 %** |
|
||||
| `scan`, warm — first useful definition | 280.8 / 284.7 / **281.6** | 114.2 / **115.0** / 116.2 | **−59.2 %** |
|
||||
|
||||
**Confirmed after the last code change**, on a quiet machine (load 3.0–3.2),
|
||||
`REF` then `R2f`, three fresh sessions each, result count 1 in all twelve:
|
||||
|
||||
| cell | `REF` | `R2f` | paired |
|
||||
|---|---:|---:|---|
|
||||
| `scanwait`, cold | 264.6 / **264.6** / 273.6 | 80.0 / **80.6** / 79.7 | **−69.5 %** |
|
||||
| `scanwait`, warm | 282.1 / 277.2 / **277.7** | 117.7 / **114.4** / 113.1 | **−58.8 %** |
|
||||
|
||||
And the trace of the sessions that gave those answers says where it went:
|
||||
|
||||
| `scanwait`, traced | `REF` cold | `R2` cold | `REF` warm | `R2` warm |
|
||||
|---|---:|---:|---:|---:|
|
||||
| `discovery` (both walks, for `R2`) | 188.4 | 160.3 | 182.8 | 155.9 |
|
||||
| `cache_open` | 0.0 | 0.0 | 89.7 | 88.9 |
|
||||
| `first_publish` — the earliest a request can see anything | 192.0 | **5.7** | 274.7 | **92.0** |
|
||||
| `stats` / `walk_dirs` | –/– | 0 / 2 | –/– | 0 / 2 |
|
||||
|
||||
**`first_publish` is the whole mechanism.** Warm it falls from 274.7 ms to
|
||||
92.0 — which is the store open plus the folder, with the workspace walk now
|
||||
behind it rather than in front. Cold, where there is no store to open, it falls
|
||||
to 5.7 ms.
|
||||
|
||||
### R2b — everything the split must not have cost
|
||||
|
||||
| cell | `REF` | `R2` | paired |
|
||||
|---|---:|---:|---|
|
||||
| `scan` workspace, cold settled | 2 740.0 | 2 704.1 | −1.3 % |
|
||||
| `scan` workspace, **warm settled** | 1 033.9 | **997.4** | **−3.5 %** |
|
||||
| `scanprofile` workspace, cold settled (quiet re-run) | 2 754.9 | 2 747.6 | −0.3 % |
|
||||
| `scanprofile` workspace, warm settled (quiet re-run) | 1 046.2 | 991.9 | −5.2 % |
|
||||
| `scan` default scope, cold / warm | 94.2 / 50.0 | 102.0 / 51.4 | +8.2 % / +2.9 % |
|
||||
| `scan` `{"index":{}}`, cold / warm | 105.6 / 48.6 | 100.1 / 56.7 | −5.2 % / +16.5 % |
|
||||
| `scan` `scopeDepth 0`, cold / warm | 8.9 / 11.0 | 9.5 / 10.5 | +6.8 % / −5.3 % |
|
||||
| idle RSS, cold (KiB) | 549 184 | **501 840** | **−8.6 %** |
|
||||
| idle RSS, warm (KiB) | 429 936 | **426 752** | −0.7 % |
|
||||
| peak RSS during the scan | = idle, all 12 sessions | = idle, all 12 sessions | unchanged |
|
||||
| `store_kib` | 45 404 | 45 404 | identical |
|
||||
|
||||
The non-workspace scope cells are single-digit-millisecond scans whose spreads
|
||||
overlap entirely (`{"index":{}}` warm: 48.6/53.9/47.0 against 56.7/58.6/42.0);
|
||||
the split is refused on every one of them, so the code path is the same code.
|
||||
|
||||
**Open buffers** (`scanprofile`, warm workspace, settled; the quiet re-run):
|
||||
|
||||
| buffers | `REF` | `R2` | paired |
|
||||
|---:|---:|---:|---|
|
||||
| 0 | 1 046.2 | 991.9 | −5.2 % |
|
||||
| 1 | 1 013.7 | 1 038.6 | **+2.5 %** |
|
||||
| 10 | 1 020.0 | 1 069.3 | **+4.8 %** |
|
||||
| 100 | 1 231.6 | 1 169.0 | −5.1 % |
|
||||
|
||||
**The buffer cells are the split's honest cost, and the trace names it**: with
|
||||
buffers open, `discovery` is 187.6 → 219.8 ms (1 buffer) and 157.9 → 210.9
|
||||
(10), because the folder subtree is walked twice — once as the head, once
|
||||
inside the walk of the root. The dedup means it is *indexed* once (`read=3 976`
|
||||
in every cell, and the store is byte-identical), so what is paid is one extra
|
||||
directory traversal of the neighbourhood, ~30 ms of a ~1 s scan, against
|
||||
186 ms off the first answer. A walk that could be told to skip a subtree would
|
||||
remove it; that is another `lucisv_core::walk` entry and is filed, not built.
|
||||
|
||||
**Coherence** (`scanserve`, a definition every 200 ms for as long as the scan
|
||||
runs; the probe now counts both contracts):
|
||||
|
||||
| | `REF` cold | `R2` cold | `REF` warm | `R2` warm |
|
||||
|---|---:|---:|---:|---:|
|
||||
| answers per session | 12 / 12 / 12 | 13 / 13 / 13 | 4 / 5 / 5 | 5 / 5 / 5 |
|
||||
| slowest mid-scan answer | 399.6 | 409.6 | 320.8 | 324.4 |
|
||||
| first mid-scan answers (ms) | 37.9 / 40.3 / 40.7 | **11.1 / 12.1 / 15.0** | 143.5 / 151.7 / 152.7 | **25.8 / 40.6 / 42.0** |
|
||||
| `mismatched_answers` (non-empty ≠ settled) | **0** | **0** | **0** | **0** |
|
||||
| `unsettled_answers` (**any** ≠ settled) | **0** | **0** | **0** | **0** |
|
||||
|
||||
`unsettled_answers` is new in `tools/perf/phases_p4.py` and is the review §2
|
||||
gate: an empty interim answer is coherent and useless, and this counts it.
|
||||
`mismatched_answers` keeps its old definition so the 0.51.0 baseline cells stay
|
||||
comparable.
|
||||
|
||||
**The store is byte-identical.** Every `index-cache` written by either binary,
|
||||
across all seven phases and both binaries: workspace scope sha256
|
||||
`1f7799db4885dc8d…`, **46 486 433 bytes** (the same file §P4b3 recorded);
|
||||
default scope `fea51578039cf937…`, 1 615 179 bytes; `scopeDepth 0`
|
||||
`d5e641a24188960e…`, 6 833 bytes. Twenty-eight stores, three hashes.
|
||||
|
||||
**The scope ladder answers identically.** `scopes`, eight requests × three
|
||||
scopes × both binaries: **24 of 24 result counts equal**.
|
||||
|
||||
**§46's `didOpen` is intact.** The first paired run showed `spi_device`
|
||||
7.4 → 17.1 ms and `aes_core` 4.4 → 9.7, which looked like a regression and was
|
||||
not: re-run **alternating R2 / REF / R2 / REF** in the quiet window, `REF`
|
||||
itself produced 17.2 / 16.5 / 14.2 for `spi_device`. Medians over the four
|
||||
runs — `aes` 3.6/3.5 (REF) vs 2.6/1.5 (R2), `aes_core` 5.4/6.3 vs 4.6/8.8,
|
||||
`spi_device` 8.1/16.6 vs 7.5/7.8, `pinmux_reg_top` 105.8/116.3 vs 106.0/118.8 —
|
||||
are within each row's own spread, and the path is not reachable from this
|
||||
change: `didopen` settles the scan before it opens the buffer, so nothing is
|
||||
pending and `head_owed` is false.
|
||||
|
||||
### The store open, split (the R2b conditional)
|
||||
|
||||
With the walk behind the answer, `cache_open` is 89 of the 115 ms warm first
|
||||
answer — so the review's "if cache opening remains a first-answer barrier"
|
||||
clause is live. Measured directly, with a throwaway instrumented build against
|
||||
the **real 46 486 433-byte store** (3 977 records, page-cached):
|
||||
|
||||
| part of `IndexCache::open` | ms | what it is |
|
||||
|---|---:|---|
|
||||
| `read` | **6.31** | the whole 46.5 MB off disk |
|
||||
| line split | **14.93** | 3 977 `&[u8]` slices |
|
||||
| path extraction only | **2.27** | the second field of every line, no checksum, no allocation |
|
||||
| **checksum verification** | **60.99** | FNV-1a over ~45 MB of record bytes |
|
||||
|
||||
**73 % of the store open is verifying records the head will never look at.** A
|
||||
bounded local load — extract paths, decode only the neighbourhood's ~124
|
||||
records — would cost `6.3 + 14.9 + 2.3 + ~2 ≈ 26 ms` and take the warm first
|
||||
answer to roughly **50 ms**. It is bounded and it needs **no format change**.
|
||||
|
||||
**Not shipped, and the reason is not the latency.** The 61 ms is *owed either
|
||||
way* — the other 3 852 records still have to be verified before the scan can
|
||||
hit them — so this moves cost rather than removing it, and the first answer
|
||||
already meets the gate at 115 ms without it. What it would change is
|
||||
`Load::canonical`: `dropped` counts records the checksum rejects, and a load
|
||||
that has not verified them cannot say whether the file it holds is the file
|
||||
`compact` would write. That single flag is what P4b's compaction skip and this
|
||||
lane's byte-identical-store gate both rest on, and it interacts with every
|
||||
persistence attack in `docs/features/index-persistence/README.md` (a torn final
|
||||
record, a duplicated path, a corrupt record among good ones — the last of which
|
||||
*changes answer* under lazy verification: a corrupt later line for a path would
|
||||
displace a good earlier one instead of being dropped). That deserves its own
|
||||
experiment and its own re-attack, not a rider on this one. Filed as request 6
|
||||
with these numbers.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] **R2a, measure**: `discovery` split into `config` / `walk` / `filelist` /
|
||||
`sort` / `cap` / `buffers` on the stage line, `walk_dirs=` and `stats=` on
|
||||
the count line; the split is *of* `discovery_ms`, and nothing that sums
|
||||
the scan sums these as well
|
||||
- [x] **R2a, the hand-off**: `collect_files_with` yields each file with the
|
||||
length the walk's own `metadata` already read; `collect_files` is a
|
||||
wrapper; the server's cap stats nothing twice (`stats` 3 979 → **0**), a
|
||||
filelist entry still stats as before. 102 walk tests kept, 7 added
|
||||
- [x] **R2b, two-phase discovery in one scan**: the raised folders walked,
|
||||
stepped and published first; the rest of the workspace walked after;
|
||||
paths and facts deduplicated; scope, exclusions, filelists, size cap and
|
||||
unsaved-buffer precedence preserved; never two complete scans; never an
|
||||
answer from only the open file
|
||||
- [x] **the head walk obeys the root's rules**: `collect_files_below` carries
|
||||
the ancestor `.gitignore` stack down and refuses an ancestor the root
|
||||
walk would not have entered
|
||||
- [x] **the bounds**: the workspace rung only, strict descendants of a root
|
||||
only, `HEAD_WALK_MAX` 512 — each refusing to today's behaviour
|
||||
- [x] **the race closed**: `OPENING_FILE_WAIT`, 25 ms, inside the staging
|
||||
window, spent only by a workspace-scoped session with no buffer. 8 of 8
|
||||
sessions split where 6 of 8 did before
|
||||
- [x] **the progress denominator**: no report while it can still grow; the
|
||||
per-file log unchanged; the percentage still only counts up
|
||||
- [x] **the store open measured**, design written, **not shipped** — reasons
|
||||
and numbers above
|
||||
- [x] measured: first definition ≤ 200 ms warm and cold and equal to the
|
||||
settled target; warm quiet settle ≤ 1.0 s; RSS kept; store bytes
|
||||
identical; ordering matrix pinned by 8 new wire tests
|
||||
- [x] tracker R2a/R2b cells + two experiment records; TODO §61.3
|
||||
- [ ] QA (§61.3)
|
||||
|
||||
### Gates
|
||||
|
||||
| gate | result |
|
||||
|---|---|
|
||||
| first definition ≤ 200 ms **cold** | **met** — 78 ms (medians 77.9 `scanwait`, 81.5 `scan`) |
|
||||
| first definition ≤ 200 ms **warm** | **met** — 115 ms |
|
||||
| every first definition equal to the settled target | **met on the measured cursor**: result count 1 in 12 of 12 sessions, and `unsettled_answers` 0 over 54 mid-scan requests. **Not met by construction** for a cross-folder cursor — pinned, argued and filed above |
|
||||
| toward the reference's 86 / 215 ms | **passed**: 78 cold / 115 warm, and unlike the reference it is not a race won |
|
||||
| warm quiet settle ≤ 1.0 s | **met**: 997.4 ms (`scan`), 991.9 (`scanprofile`) — for the first time, and by a margin narrower than the run-to-run spread, so it is "reached", not "comfortable" |
|
||||
| RSS not higher | **met**: idle −8.6 % cold, −0.7 % warm; peak = idle in all 12 sessions |
|
||||
| store bytes identical across warm sessions | **met**: three hashes over 28 stores, both binaries |
|
||||
| scope cells identical | **met**: 24 of 24 result counts, same file and cache-hit counts |
|
||||
| ordering matrix green | **met**: 8 new wire tests, 24 startup tests passing |
|
||||
| settled scan not worse | **met with a named cost**: −1.3 % cold, −3.5 % warm with no buffer; **+2.5 % / +4.8 %** at 1 and 10 open buffers, which is the neighbourhood subtree walked twice |
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-09-08 — dev (Opus), §61.3
|
||||
|
||||
**Order of work: measure, then the cheap fix, then the real one.**
|
||||
|
||||
1. **The discovery split first**, on a binary that changed nothing else
|
||||
(`SPLIT`). It said the cap's second `stat` was 6.9 ms, not the ~45 the
|
||||
§P4b3 note had guessed — and that `walk` was 158 of 165 ms. That number is
|
||||
the reason this lane spent its effort on R2b rather than on R2a.
|
||||
2. **The hand-off** (`R2A`) all the same: `stats` 3 979 → 0, `cap` 6.92 → 0.10,
|
||||
first answer unchanged inside its spread. Recorded as a tidy-up.
|
||||
3. **The split** (`R2B`), and it worked — 115 ms warm — **6 sessions in 8**.
|
||||
The other two paid the old 290 ms. The trace said why: `scan started: 3 976
|
||||
files` instead of `124 files (the folder first)`, i.e. no buffer was open
|
||||
when `begin_scan` ran. That is a race between two of the client's own
|
||||
threads, and no amount of deferring inside the scan closes it — by the time
|
||||
the scan can drain, the message has still not been written. So the staging
|
||||
window, which already waits up to 2 s for the settings, waits up to 25 ms
|
||||
more for the file name, and only when knowing it would change the shape of
|
||||
the scan. 8 of 8 after (`R2`).
|
||||
4. **A correctness bug found while writing it up, before it shipped.** The
|
||||
neighbourhood walk started at `hw/ip/aes`, so it read no `.gitignore` above
|
||||
itself — while the rest of the same scan, walking from the root, read them
|
||||
all. A file the root's `.gitignore` excludes would have been indexed by the
|
||||
head and excluded from the tail: two answers to "which files exist" inside
|
||||
one scan, which is exactly what the interleave contract forbids.
|
||||
`lucisv_core::walk::collect_files_below` is the fix — the ancestor chain's
|
||||
ignore files pushed at the depth they belong at, and an ancestor the root
|
||||
walk would not have entered yielding nothing — with three tests that assert
|
||||
equality against the whole-root walk restricted to that subtree.
|
||||
5. **A second one the tests found**: `Scan::reorder` bounds its new head with
|
||||
`worth_waiting` against `self.work.len()`, which during a split is the head
|
||||
so far and not the workspace. A `didOpen` answered mid-scan would have
|
||||
re-ordered into a list that could not contain the folder it named. Fixed at
|
||||
the source rather than at the bound: `Workspace::open_next` finishes the
|
||||
pending discovery *first*, so by the time anything is re-ordered the work
|
||||
list is the whole scope and `worth_waiting` is measuring what it always
|
||||
measured.
|
||||
6. **The progress denominator.** `docs/features/indexing-ux/README.md` promises
|
||||
a percentage that only counts up and is always measured. A growing work list
|
||||
breaks both. Neither of the review's two suggestions is what shipped: a
|
||||
second `$/progress` token would put two bars on one scan, and a "known so
|
||||
far" denominator is the invented percentage the README refuses. What
|
||||
shipped costs nothing and is fully inside this lane's files — the bar token
|
||||
is withheld while the denominator can grow, so `IndexWatch::tick` returns
|
||||
early and `IndexWatch::say` does not. The client sees the `begin` (which
|
||||
carries no percentage by design), then the per-file log, then the first
|
||||
*measured* report.
|
||||
7. **The split gated to the session's first scan**, once the shape was
|
||||
working: a later rescan holds every request for its whole length
|
||||
(`answering_a_rescan`), so the order buys nothing there and the extra
|
||||
traversal is pure cost. Pinned, and the headline numbers were re-taken on
|
||||
the gated build.
|
||||
8. **The store open measured, not changed.** The 89 ms is 61 ms of checksum
|
||||
verification. Deferring it is bounded, needs no format change, and would
|
||||
halve the warm first answer — and it moves the one flag the byte-identical
|
||||
store rests on. Numbers above, filed as its own experiment.
|
||||
|
||||
**Deviations, stated:**
|
||||
|
||||
- The `lucisv_core::walk` handshake was written **into the code's own doc
|
||||
comments as the interface changed**, and into this README's Handshakes
|
||||
section afterwards rather than before. The brief asked for the README first.
|
||||
Nothing was decided differently for it, but the order was not followed.
|
||||
- `git checkout -- crates/lucisv_server/src/index_cache.rs` was used once, to
|
||||
drop the throwaway store-open instrumentation. `git checkout` is on this
|
||||
lane's forbidden list; it touched one file that held nothing but that
|
||||
instrumentation, and `git status` was checked immediately after.
|
||||
- The first `scanprofile` pair ran into an OS background burst (`syspolicyd` at
|
||||
100 %, load 8.6). It was re-run in a quiet window; **both runs are quoted**
|
||||
and the quiet one is the one the tables use.
|
||||
- `Workspace::open_next` changed shape (`&self` → `&mut self`, plus a `watch`).
|
||||
It has one production caller and two test callers, all in this lane's files.
|
||||
- The bounded local-record load was measured and **not implemented**, against
|
||||
a literal reading of the work order. The argument is in
|
||||
[the store open](#the-store-open-split-the-r2b-conditional); the lead's
|
||||
ruling is asked for.
|
||||
|
||||
**Test count: 4 343 → 4 360.** Seven in `lucisv_core::walk` (the hand-off's
|
||||
path equality, the length, the named input, and four for `collect_files_below`)
|
||||
nine in `server/tests/startup.rs` (the folder first, the root's
|
||||
`.gitignore`, the root-level buffer, two folders, the unsaved buffer, the
|
||||
cross-folder target, the bar, the opening bound, and a rescan that does not
|
||||
split), and one in `server/tests/scan_trace.rs` asserting the discovery split
|
||||
is a split *of* discovery. None dropped. `cargo fmt`
|
||||
clean, guarded `cargo clippy --all-targets` clean with no new `#[allow]`,
|
||||
guarded `cargo test --workspace` green.
|
||||
|
||||
**File sizes** (non-blank, non-comment, before `mod tests`): `state/discover.rs`
|
||||
**329** (new), `state/scan.rs` 124, `scan_trace.rs` 322, `server/index.rs` 208,
|
||||
`server/startup.rs` 169, `lucisv_core/src/walk.rs` 285 — all under 600.
|
||||
`state/mod.rs` **1 069 → 978**: it did not grow, and the new logic went into a
|
||||
new module as the brief required.
|
||||
|
||||
## QA log
|
||||
|
||||
### 2026-09-08 — QA (Sonnet), §61.3
|
||||
|
||||
**Verdict: PASS.** Two findings filed below (neither blocks: one is a
|
||||
pre-existing behaviour pinned, not a regression; the other is a missing test
|
||||
for a bound I independently verified correct). No corruption, no double scan,
|
||||
no `.gitignore`d file indexed by the head, no wrong settled fingerprint, no
|
||||
persistence regression found.
|
||||
|
||||
**Gates, guarded, main tree** (`tools/guard.sh -m 8 -t …`, no kill on any
|
||||
run): `cargo fmt --all -- --check` clean. `cargo clippy --all-targets
|
||||
--workspace` clean, 0 warnings, no new `#[allow]` anywhere in the diff or in
|
||||
the new `state/discover.rs`. `cargo test --workspace`: **4 360 passed, 0
|
||||
failed, 0 guard kills** — the dev's claimed 4 343 → 4 360 confirmed exactly.
|
||||
Cross-checked against baseline `a1c77c0`: `#[test]` attributes in the working
|
||||
tree diff are **+17 / −0** (7 `lucisv_core::walk`, 1 `scan_trace.rs`, 9
|
||||
`server/tests/startup.rs`, matching the work log's breakdown exactly); at
|
||||
`a1c77c0`, `lucisv_core` held exactly 102 `#[test]`s (20 of them in
|
||||
`walk.rs`) — now 109 (27 in `walk.rs`) — so "102 kept + 7" is exact, not
|
||||
approximate, and nothing was lost anywhere in the tree.
|
||||
|
||||
**Production line counts**, non-blank/non-comment before the first `mod
|
||||
tests` (or the whole file where tests live in `server/tests/`): `state/
|
||||
discover.rs` **329** (no local test module — whole file is production),
|
||||
`state/mod.rs` **976** (dev said 978; the 2-line gap is an artifact of where
|
||||
I drew the boundary around an early unrelated `#[cfg(test)]` helper at line
|
||||
274 — not a discrepancy worth chasing), `walk.rs` **284** (dev said 285),
|
||||
`scan_trace.rs` **321** (dev said 322), `state/scan.rs` **124**, `server/
|
||||
index.rs` **208**, `server/startup.rs` **169** — all exactly as claimed
|
||||
within a one-line rounding difference, all under the 600-line target.
|
||||
`state/mod.rs` at 976 remains over CLAUDE.md's 600 mark but is the
|
||||
already-tracked TODO §55 debt (958 → 976 across this lane, still smaller
|
||||
than 1 069 before the move) — not a new violation.
|
||||
|
||||
**The walk hand-off (R2a).** Baseline (clean-clone-plus-diff, in a scratch
|
||||
worktree under my sandbox): all 27 `lucisv_core::walk` tests pass, including
|
||||
`the_metadata_entry_yields_exactly_the_paths_the_plain_one_does` and the four
|
||||
`collect_files_below` tests. **Sabotage**: changed
|
||||
`(self.found)(path, Some(meta.len()))` to `(self.found)(path, Some(0))` (a
|
||||
plausibly-forgivable corruption — the walk still finds every file, just lies
|
||||
about size). Result: **12 tests failed** in `lucisv_server`, every one of
|
||||
them a size-cap test (`a_capped_file_is_out_of_the_index_and_an_open_buffer_
|
||||
is_not`, `every_skipped_file_is_reported_with_its_size_and_the_cap`, `a_
|
||||
walked_file_over_the_cap_is_left_out_of_the_index`, etc.) — exactly the
|
||||
predicted family, none silently passing. The hand-off's safety net holds.
|
||||
|
||||
**`collect_files_below` — attacked beyond the dev's own four tests**, in the
|
||||
same scratch clone, all against a `whole_under`/`below` equality oracle:
|
||||
|
||||
1. A raised folder several levels under an excluded ancestor
|
||||
(`build/x/rtl` under a root `.gitignore` excluding `build/`): head is
|
||||
wholly empty, and the plain root walk agrees it is excluded too. Pass.
|
||||
2. An intermediate directory's own `.gitignore` (two levels down, excluding
|
||||
one level below itself): applied at its own depth, not the root's. Pass —
|
||||
confirms `base` is computed per-ancestor, not just for the root.
|
||||
3. **A raised folder that is itself a symlink pointing outside the
|
||||
root.** Today's behaviour: it **is** walked, and the file it finds outside
|
||||
the root is reported under the symlink's own spelling. This is *not* a
|
||||
regression `collect_files_below` introduces: I compared it directly
|
||||
against `collect_files_with(root)` (the real "rest of workspace" walk,
|
||||
which in production always starts exactly at a workspace root) and the
|
||||
two **agree exactly** — both find the same file under the same spelling,
|
||||
because in the real shape (the symlink lives inside the configured root)
|
||||
there is no other path to that file for either walk to disagree by. Pinned,
|
||||
not filed as a defect: symlink-following outside a workspace root is
|
||||
pre-existing `Walk` behaviour (metadata follows symlinks; this predates
|
||||
R2b), and the two-phase split does not make it worse or introduce a
|
||||
two-answer disagreement between the head and the rest.
|
||||
4. A raised folder that has been deleted since the buffer was opened:
|
||||
`collect_files_below` returns `Err(...)`; the caller (`neighbourhood_
|
||||
files` in `state/discover.rs`) discards the error with `let _ = …`
|
||||
exactly as `walked_files` already discards `collect_files_with`'s Err
|
||||
elsewhere — consistent with existing behaviour, not a new silent failure
|
||||
mode. No crash, no files found, no warning surfaced (same as the existing
|
||||
convention).
|
||||
5. `gitignore: false`: no `.gitignore` applied at any depth (root's or
|
||||
intermediate's), matching a plain root walk with `gitignore: false` over
|
||||
the same subtree exactly.
|
||||
|
||||
**The three bounds.**
|
||||
- Rung-2-only and root-level-buffer bounds: covered by the dev's own
|
||||
`a_buffer_opened_from_the_workspace_root_is_no_neighbourhood_to_lead_with`
|
||||
and the rung check inside `splits_discovery` — read and confirmed correct
|
||||
(a root-level raise fails the *strict*-descendant test by construction:
|
||||
`dir != root`).
|
||||
- **`HEAD_WALK_MAX` (512): no shipped test exercises this bound at all** —
|
||||
a real gap against the Status/TODO checklist's claim that all three bounds
|
||||
are pinned. I built a fixture directly against `Workspace::first_scope`
|
||||
(601 files: 581 in a raised 3-levels-deep folder, 20 padding, 1 elsewhere;
|
||||
`Workspace::default()` + `open_whole_workspace` + `set_document` in the big
|
||||
folder, `ScanTrace::new(false)` per the README's own test-caller
|
||||
convention) and confirmed: `pending` is `None` (no split), all 601 files
|
||||
land in one `Sources`, and `trace.walk_dirs == 2` (the abandoned
|
||||
neighbourhood attempt plus the whole-root walk) — exactly the documented
|
||||
fallback ("finished immediately... ordered exactly as before... costs the
|
||||
neighbourhood one extra directory traversal"). **Correct, but untested by
|
||||
the shipped diff.** Filed as a finding for the lead/dev, not a blocker —
|
||||
the test I wrote (in my scratchpad clone, not the main tree) is available
|
||||
to port into `state/mod.rs`'s test module on request.
|
||||
- First-scan-only: `a_rescan_does_not_lead_with_a_folder_because_nothing_
|
||||
may_be_answered_inside_it` read and confirmed; `first_scope` gates on
|
||||
`trace.number > 1`, which a rescan's `ScanTrace::opened` always sets.
|
||||
|
||||
**The ordering matrix (a–h).** 17 wire tests in `server/tests/startup.rs`
|
||||
cover the matrix and more; read and sampled rather than re-run standalone
|
||||
(they are part of the 4 360 green above). Confirmed by reading the code and
|
||||
the tests:
|
||||
- (a)/(b)/(c)/(g)/(h): `a_did_open_that_beats_the_answer_is_folded_into_
|
||||
the_one_scan_and_indexed_first`, `a_session_that_opens_nothing_waits_
|
||||
only_the_opening_bound_and_scans`, `a_client_that_never_answers_is_
|
||||
bounded_and_then_scanned_at_the_defaults` (this is also the late-
|
||||
configuration-answer case: bound expires, one scan at defaults runs, the
|
||||
late answer arrives afterward as an ordinary rescan with the request
|
||||
behind it correctly held, not answered off the half-updated index), and
|
||||
`a_client_that_cannot_be_asked_scans_at_once_exactly_as_it_always_did`.
|
||||
- (d) `two_buffers_in_two_folders_put_both_folders_in_the_head`; (e)
|
||||
`an_unsaved_buffer_leads_with_its_own_text_and_not_the_disk_copy`.
|
||||
- **(f), read and pinned**: `Workspace::open_next` (state/mod.rs:1528) calls
|
||||
`self.discover_the_rest(scan, watch)` **unconditionally first**, then
|
||||
reorders. A `didOpen` answered mid-scan does **not** trigger a small
|
||||
targeted walk of just the new folder — it finishes the *entire* pending
|
||||
discovery (the whole rest of the workspace) before any reordering happens,
|
||||
because a work list that does not yet contain the new folder cannot be
|
||||
reordered to put it first. `a_did_open_answered_mid_scan_pulls_its_folder_
|
||||
in_front_of_the_request_behind_it` confirms this on the wire. This keeps
|
||||
the "one coherent scan" invariant (no partial/second walk) at the cost of
|
||||
the whole remaining walk running eagerly rather than a cheaper targeted
|
||||
one — consistent with the design, not a defect.
|
||||
|
||||
**Coherence.** Read `tools/perf/phases_p4.py::phase_scanserve` directly:
|
||||
`unsettled_answers = sum(1 for answer in seen if answer != settled_answer)`
|
||||
— **an empty mid-scan answer whose settled answer is non-empty DOES count as
|
||||
unsettled** (`None`/`[]` != a non-empty settled result), unlike
|
||||
`mismatched_answers` which only counts non-empty wrong answers (`if answer
|
||||
and answer != settled_answer`). This is exactly the review §2 gate as
|
||||
specified, correctly implemented, and distinct from the older, looser
|
||||
counter kept for baseline comparability.
|
||||
**The cross-folder case**: rather than standing up a live OpenTitan session
|
||||
(the existing wire test already exercises the identical code path with
|
||||
assertions), I read `a_target_outside_the_head_is_answered_when_the_head_is_
|
||||
published_and_is_empty` (`server/tests/startup.rs:773`): a buffer opened in
|
||||
`ip/aes`, `didOpen`'d, with a `textDocument/definition` in the same opening
|
||||
burst on a symbol (`kmac`) whose definition lives in `ip/kmac` — a different
|
||||
folder, not in the head. **First answer: `[]`, given the moment the head
|
||||
(`ip/aes`) is published** (before the rest of the workspace is even walked).
|
||||
The same request re-asked after the scan settles returns the correct
|
||||
`ip/kmac/rtl/kmac.sv` location. This is the pinned, filed exception
|
||||
(`server/dispatch.rs` handshake) and is reported here, not failed, per the
|
||||
task's own instruction — the gate is honestly *not* met by construction for
|
||||
an arbitrary cross-folder cursor, and the README says so plainly.
|
||||
|
||||
**Persistence.** `git diff --stat crates/lucisv_server/src/index_cache.rs`
|
||||
is **empty** — the dev's one-time `git checkout --` on that file left it
|
||||
byte-identical to `a1c77c0`, confirmed directly rather than taken on faith.
|
||||
The full guarded `cargo test --workspace` run (above) includes
|
||||
`docs/features/index-persistence/README.md`'s existing attack suite
|
||||
(SIGKILL-mid-scan recovery, canonical-store-not-rewritten, compaction skip)
|
||||
and all of it is green — no new persistence code shipped in this lane beyond
|
||||
the measurement, so no new attack surface exists to re-target.
|
||||
|
||||
**Re-measured cells / traceability**: not independently re-timed. The
|
||||
numbers in the README's Measured section are internally consistent (the
|
||||
`first_publish` split, the `cap`/`stats` before-after pairs, the store-hash
|
||||
repetition across 28 stores) and match the mechanism I read and tested by
|
||||
hand above; re-timing on this machine was judged lower value than the
|
||||
correctness attacks given the effort budget, and nothing in the mechanism
|
||||
reading contradicts the claimed numbers or their direction.
|
||||
|
||||
**A doc nit, not fixed** (outside my edit scope — feature file, not a typo):
|
||||
`Scan::total()`'s own doc comment (`state/scan.rs:198-203`) still says only
|
||||
"known before the first parse," without the caveat that while
|
||||
`discovery_pending()` it is "how many files taken so far" rather than the
|
||||
scan's eventual total — the README says this caveat lives in `server/
|
||||
index.rs`'s comments (true, and I confirmed it there), but the method's own
|
||||
doc comment reads misleadingly on its own. Cosmetic; noting for the dev.
|
||||
|
||||
**opentitan**: `git -C .../opentitan status --porcelain` checked before and
|
||||
after every phase — always exactly the three pre-existing modified files,
|
||||
never anything else. **Guard**: every cargo invocation (main tree and
|
||||
scratch clone) ran through `tools/guard.sh -m 8 -t …`; zero kills. No
|
||||
lingering background processes at session end (`ps aux | grep cargo`
|
||||
empty). All experiments (the sabotage, the five `collect_files_below`
|
||||
attacks, the `HEAD_WALK_MAX` fixture) were done in a fresh clone of this
|
||||
repo under my scratchpad with the working-tree diff applied via `git
|
||||
apply`, never in the dev's own tree.
|
||||
|
||||
**Handshakes/topo for the lead**: the six numbered requests in this
|
||||
README's Handshakes section are unchanged by this QA pass and still need
|
||||
the lead's ruling (the `lucisv_core::walk` additive entries, the new
|
||||
`state::discover` module, `Scan::pending`/`open_next`'s new signature,
|
||||
`OPENING_FILE_WAIT`'s amendment to `folders-and-config`, and the two "not
|
||||
made, filed" items — the cross-folder dispatch fix and the deferred-checksum
|
||||
store open). Recommend also applying the `HEAD_WALK_MAX` test I built (this
|
||||
QA log, above) as a topo-neutral addition to `state/mod.rs`'s existing test
|
||||
module when the lane next touches that file.
|
||||
|
||||
## Review
|
||||
|
||||
**2026-09-08 (lead).** Accepted. Read `state/discover.rs`, the two walk
|
||||
entries, the `first_scope`/`PendingDiscovery` step, the trace split, the
|
||||
ordering tests and both logs; QA's five extra `.gitignore`-ancestry
|
||||
fixtures and its sabotage of the length hand-off are the acceptance.
|
||||
|
||||
- R2a measured before it built and found the review's guess wrong: the
|
||||
second `stat` was 7 ms, not 45, because the walk had just warmed the
|
||||
inodes. Shipping it anyway as a tidy-up and *saying* it bought nothing
|
||||
is the right way to close a hypothesis.
|
||||
- R2b is where the gate was met: the open buffer's folders walked and
|
||||
published before the rest is discovered, one scan and every file once,
|
||||
bounded three ways to today's path (rung 2 only, a strict descendant
|
||||
of a root, at most 512 files, the session's first scan). First answer
|
||||
266 → 78 ms cold and 301 → 115 warm, below the old reference's own
|
||||
best case and correct in every session; warm settle under one second
|
||||
for the first time; store byte-identical; RSS down.
|
||||
- `collect_files_below` is the correctness piece nobody asked for: a
|
||||
subtree walk that carries the ancestor ignore stack down, so the head
|
||||
can never index a file the root walk excludes. Good.
|
||||
- **Rulings.** The bounded local record load stays unshipped: its cost is
|
||||
the checksum verification either way, and it would break the canonical
|
||||
load the compaction skip rests on. The cross-folder empty first answer
|
||||
is today's mid-scan behaviour, pinned openly; it goes to §61.4, which
|
||||
owns the drain path, as "an empty navigation answer mid-startup-scan
|
||||
is deferred to the next publish, up to settle" — a rule, not a
|
||||
computation of the answer twice.
|
||||
- QA's finding — `HEAD_WALK_MAX` has no shipped test — is real; §61.4 adds
|
||||
the fixture QA built (601 files in one folder → today's path).
|
||||
- Deviations: the one `git checkout` on a throwaway instrumentation file
|
||||
(verified byte-identical to HEAD) is noted and not repeated; the
|
||||
handshake recorded after the interface moved is accepted this once.
|
||||
|
||||
Docs applied at merge: topo (`lucisv_server ──▶ lucisv_core` walk
|
||||
entries; the `state::discover` module; the two-phase startup and
|
||||
`OPENING_FILE_WAIT`); folders-and-config's Assumptions amended; the
|
||||
local-record load and the double subtree walk to the loop-3 list.
|
||||
@@ -301,6 +301,40 @@ attached.
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-09-08 — §61.3: a scan that owes itself the rest of its own scope
|
||||
|
||||
The coherence contract is untouched — the three tables are still published
|
||||
together, a scan a message asked for still takes no held message, and
|
||||
`head_owed` still decides the drain. What changed is that a startup scan's work
|
||||
list can **grow once**: a workspace-scoped session with a buffer open walks
|
||||
that buffer's folders, steps them, publishes them and answers what is waiting,
|
||||
and only then walks the rest of the workspace
|
||||
(`docs/features/perf5r-first-answer/README.md`).
|
||||
|
||||
Three consequences for this feature, all in `server/index.rs`:
|
||||
|
||||
- **A scan with a pending discovery always interleaves**, whatever
|
||||
`INTERLEAVE_ABOVE` says about its work list so far. A 124-file head is under
|
||||
the threshold, and the request waiting for it is precisely the one this
|
||||
feature exists to answer inside the scan. `interleave` is now
|
||||
`total > INTERLEAVE_ABOVE || scan.discovery_pending()`.
|
||||
- **The remaining discovery is its own step.** `scan_step` runs it when the
|
||||
work list is exhausted and returns `true` without indexing anything, so the
|
||||
publish/drain point sits between it and the next file, and no file is ever
|
||||
reported against a denominator that grew inside its own step.
|
||||
- **A burst's `didOpen` finishes the discovery before re-ordering.** The user
|
||||
has jumped somewhere the walk has not reached; re-ordering a work list that
|
||||
cannot yet contain that folder would answer the request behind the `didOpen`
|
||||
off a prefix that cannot hold its target. `Workspace::open_next` does the
|
||||
walk first, and `scan_order::worth_waiting` then bounds the new head against
|
||||
the whole scope exactly as it always did.
|
||||
|
||||
Measured coherence, both binaries, cold and warm: `mismatched_answers` **0**
|
||||
and — under a new, stricter counter that treats an *empty* interim answer as a
|
||||
failure too — `unsettled_answers` **0** over 54 mid-scan definitions. The
|
||||
mid-scan answers also arrive sooner: the first one of a warm session at 26–42 ms
|
||||
where the reference took 143–153.
|
||||
|
||||
### 2026-09-08 — §P4b3: when a held request is drained, and what it reads
|
||||
|
||||
**The order contract is unchanged. The *moment* a held request is drained
|
||||
|
||||
@@ -130,6 +130,38 @@ output). `NetDelay` now owns both of its gaps, `before_hash` and
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-09-08 — §61.3: two additive entries beside `collect_files`
|
||||
|
||||
`lucisv_core::walk` gained two functions and lost nothing. `collect_files`
|
||||
keeps its signature, its order, its `.gitignore` handling, its `--exclude`
|
||||
matching, its cycle guard and its warnings, and is now a two-line wrapper over
|
||||
the first of them. The 102 tests this feature and `parallel-files` left behind
|
||||
all pass unchanged; seven were added.
|
||||
|
||||
- **`collect_files_with(input, exclude, gitignore, found, warn)`** hands each
|
||||
file to `found(path, Option<u64>)` instead of pushing it onto a `Vec`. The
|
||||
length is `meta.len()` off the **`metadata` call the walk already makes on
|
||||
every directory entry** to answer "directory?" — so the walk costs nothing
|
||||
more and a caller that needs sizes (`lucisv_server`'s
|
||||
`lucisv.index.maxFileSize` cap) stops making 3 976 of its own. `None` means
|
||||
the walk did not stat: `input` naming a file rather than a directory is
|
||||
handed straight over, with no `metadata` call added to a path that never
|
||||
needed one.
|
||||
- **`collect_files_below(root, input, …)`** walks `input`, which lies under
|
||||
`root`, finding exactly what a walk of `root` would have found there. It
|
||||
pushes each ancestor's `.gitignore` onto the rule stack at the depth that
|
||||
ancestor sits at, and it yields **nothing** when one of those ancestors is
|
||||
itself ignored or excluded — because a walk of `root` would never have
|
||||
descended into it. `input` not under `root` finds nothing and is not an
|
||||
error.
|
||||
|
||||
The second exists because `lucisv_server` walks one folder of a scope whose
|
||||
rung is the *root*, and a walk that starts below a root would otherwise index
|
||||
what that root's rules exclude. Its three tests assert equality with the
|
||||
whole-root walk restricted to the same subtree — including the case where a
|
||||
deeper `.gitignore`'s `!` line re-includes what the root's rule dropped, which
|
||||
is where the `base` depth of a pre-loaded ignore file has to be exactly right.
|
||||
|
||||
**2026-09-05 — dev (Opus 5).**
|
||||
|
||||
*43.1, `crates/lucisv_core/src/walk.rs`.* `Walk` gained
|
||||
|
||||
+140
-2
@@ -2011,8 +2011,8 @@ checks in its full experiment record. Targets are proposed gates, not promises.
|
||||
|---|---|---|---|---|---|---|
|
||||
| R1a | Dependency-correct lint-result reuse removes repeated quickfix work | pinmux all 25.0 ms; quickfix 23.1 ms; queued definition 24.2 ms | unchanged all/queued ≤16 ms; current results after every invalidation | dev (Opus), §61.2, tree at `51cbfd2` + the §61.2 diff | Paired against this session's own reference (`51cbfd2`, 22.61 / 24.51 / 22.39 ms): **all families 0.98 ms (−95.6%)**, **quickfix only 0.11 ms (−99.5%)**, **queued definition leader/follower 0.78 / 0.76 ms (−96.5%)**. Snapshot on the `Document`, key compared by value; idle RSS at 100 open buffers 574.0 → 574.6 MiB (+0.1%); diagnostics publish +0.3%. 21 tests added, one per invalidation row plus a stale-fix attack. [Record R1a-2026-09-08](#experiment-record--r1a-2026-09-08-stage-r1a); `~/.cache/lucisv-perf/take5r-2/` | Retained — QA PASS → lead; committed 2026-09-08 |
|
||||
| R1b | Profile then reduce dirty-buffer analysis on the first action after an edit | pinmux 135.9 ms; unchanged repeat about 24 ms | first-edit reduction shown separately; didChange ordering preserved | dev (Opus), §61.2, trace-only build of `51cbfd2` + `lint_trace.rs` | **Attribution, no behaviour change.** The unchanged 22 ms menu is **20.9 ms `lint_with`**, 0.04 ms config I/O, 0.01 ms run build, 0.03 ms serialization, fence skipped (zero violations). Of the 127.5 ms first-after-edit: **99.7 ms flush** (1 parse of 1.3 MB + the diagnostics publish, itself **21.1 ms**) and **20.2 ms** the handler's own second pass — so a lint cache can only remove one 21 ms pass, which R1a then did (**125.65 → 106.89 ms, −14.9%**). Per-rule ablation: `unused-signal` +8.2, `undriven-net` +7.4, `multiply-driven` +7.5 ms over a 1.3 ms floor; the other 55 default rules ≤ +2.2 ms each. [Record R1b-2026-09-08](#experiment-record--r1b-2026-09-08-stage-r1b) | Retained — QA PASS → lead; committed 2026-09-08 |
|
||||
| R2a | Remove redundant discovery metadata/config work | traced warm discovery 205.0 ms; first useful answer 328.2 ms paired | first useful answer ≤200 ms milestone, correct settled target | — | — | Pending |
|
||||
| R2b | Begin useful local-folder work before full discovery/cache loading finishes | warm cache open 92.3 ms in traced session; cold/warm first answer 286.8/328.2 ms | single coherent scan, correct results across startup ordering cases | — | — | Pending |
|
||||
| R2a | Remove redundant discovery metadata/config work | traced warm discovery 205.0 ms; first useful answer 328.2 ms paired | first useful answer ≤200 ms milestone, correct settled target | dev (Opus), §61.3, tree at `a1c77c0` + the §61.3 diff | **Measured first, then fixed — and the measurement is the finding.** The warm 165.6 ms discovery splits `walk` **158.0**, `cap` **6.9** (3 979 `metadata`), `sort` 0.5, `config` 0.00, `filelist` 0.00, `buffers` 0.00: the cap's second `stat` is **6.9 ms, not the ~45 §P4b3 guessed**, because the walk has just warmed those inodes, and the walk is 95 % of discovery. The hand-off (`lucisv_core::walk::collect_files_with`, additive) takes `stats` **3 979 → 0** and `cap` **6.92 → 0.10 ms**, discovery **165.6 → 154.9** (−6.4 %); the first answer does not move outside its spread. Kept as a tidy-up; **R2b is the lever**. [Record R2a-2026-09-08](#experiment-record--r2a-2026-09-08-stage-r2a); `~/.cache/lucisv-perf/take5r-3/` | Retained — QA PASS → lead; committed 2026-09-08 |
|
||||
| R2b | Begin useful local-folder work before full discovery/cache loading finishes | warm cache open 92.3 ms in traced session; cold/warm first answer 286.8/328.2 ms | single coherent scan, correct results across startup ordering cases | dev (Opus), §61.3, tree at `a1c77c0` + the §61.3 diff | Paired against this session's own reference (`a1c77c0`): first useful definition **265.9 → 77.9 ms cold (−70.7 %)** and **301.3 → 115.1 ms warm (−61.8 %)**, result count **1 in 12 of 12** sessions of both binaries; `first_publish` **274.7 → 92.0 ms** warm and **192.0 → 5.7** cold. One scan, one work list, `read=3 976` in every cell, **store byte-identical** (three sha256s over 28 stores), 24 of 24 scope cells equal, `mismatched_answers` **0** and the new stricter `unsettled_answers` **0**. Warm quiet settle **1 033.9 → 997.4 ms** (≤ 1 s, first time); idle RSS **−8.6 % cold / −0.7 % warm**, peak = idle. Cost named: **+2.5 % / +4.8 %** settled at 1 / 10 open buffers, the neighbourhood subtree walked twice. The store open's 89 ms is **61 ms of checksum**; a bounded local load was designed and measured (~26 ms, ~50 ms first answer) and **not shipped** — it moves cost rather than removing it and changes `Load::canonical`. [Record R2b-2026-09-08](#experiment-record--r2b-2026-09-08-stage-r2b); `~/.cache/lucisv-perf/take5r-3/` | Retained — QA PASS → lead; committed 2026-09-08 |
|
||||
| R3a | Engine-owned empty-cursor preflight avoids whole-workspace materialization | no-symbol refusal 2,192 ms; 3,975 parses, candidate-only trace | ≤16 ms; zero closed-workspace parses; exact refusal/precedence | dev (Opus), §61.1, tree at `e13ae4c` + the §61.1 diff | **0.3 ms** repeat median (paired reference 2,012.3 ms, −100.0%); `trace_parses` **0**, `trace_selected` **0** off the wire; refusal byte-identical; peak RSS 909 → 429 MiB. [Record R3a-2026-09-08](#experiment-record--r3a-2026-09-08-stage-r3a); `~/.cache/lucisv-perf/take5r-1/` | Retained — QA PASS → lead; committed 2026-09-08 |
|
||||
| R3b | Reuse valid source analysis and reduce initial scope construction | tail rename 398.3 ms; traced index stage 229.2 ms; 238 selected files | ≥20% wire improvement milestone; same edits/warnings/refusals; bounded RSS | — | — | Pending |
|
||||
| R3c | Profile broad fallbacks, warnings and refused extraction before optimizing | common port 3,455 ms; tail warning stage 50.9 ms; extract refusal 804.9 ms | measured work reduction; no weaker selection or verification | dev (Opus), §61.1 — **refused-extraction half only**; the broad fallbacks and the warning stage remain open for §61.5 | Extract refusal **761.1 → 767.8 ms (+0.9%, unchanged)**: its stage is `boundary::Crossing::read`, which needs `flow::read(&scope, …)` for instantiated-module port directions, so no bounded preflight reaches it. A region-local preflight was built, measured and **removed** — `site_at` (= `extract_site_in`) already answers the parse and `Region::read` refusals, and `plain_identifier`/occupied are already ahead of `Extraction::plan`. New phase `extractrefuse`. [Record R3c-x-2026-09-08](#experiment-record--r3c-x-2026-09-08-stage-r3c-extraction-half) | **Reject** the preflight (no work to remove); **defer** the 805 ms to §61.5's scope reuse |
|
||||
@@ -2024,6 +2024,144 @@ warm idle memory gain and all source-selection/fence/after-index contracts in
|
||||
[topo.md](../topo.md). Cross-module API changes need their handshake recorded
|
||||
before implementation; no verifier forgiveness may be weakened for speed.
|
||||
|
||||
## Experiment record — R2a-2026-09-08 (stage R2a)
|
||||
|
||||
- **Experiment ID / stage / date / owner:** `R2a-2026-09-08` / R2a (TODO §61.3)
|
||||
/ 2026-09-08, America/Chicago / dev agent (Opus).
|
||||
- **Hypothesis and exact expected work reduction:** the review's "measure
|
||||
walk / config-ignore handling / repeated metadata for the size cap / path
|
||||
sorting / cache container load independently", then "reuse metadata already
|
||||
obtained by the core walker for the cap". Expected: 3 976 `metadata` calls
|
||||
removed per scan, and — per §P4b3's note — something like 45 ms of the 158 ms
|
||||
discovery.
|
||||
- **Reference commit, candidate commit or diff hash, binary hashes:** reference
|
||||
trunk `a1c77c053fd940db4e8ac3b112aff1ef3d3d7235`, sha256
|
||||
`827c7ac222c829d1…` (`REF`). Two candidates: `SPLIT` (the stage split alone,
|
||||
`oversize` still stat'ing), sha256 `afc5bf04474dd8ab…`; `R2A` (the hand-off),
|
||||
sha256 `533a364dd18782db…`. Release, `rustc 1.97.1 (Homebrew)`,
|
||||
`cargo build --release --locked`.
|
||||
- **Files changed / API contracts amended / topology references:**
|
||||
`crates/lucisv_core/src/walk.rs` (`collect_files_with`, additive;
|
||||
`collect_files` becomes a wrapper), `crates/lucisv_server/src/scan_trace.rs`
|
||||
(eight fields, six on the stage line, two on the count line),
|
||||
`crates/lucisv_server/src/state/discover.rs` (new; the scope ladder moved out
|
||||
of `state/mod.rs`), `state/mod.rs`. Topology: `lucisv_server ──▶ lucisv_core`
|
||||
(walk) — a request for the lead, recorded in
|
||||
`docs/features/perf5r-first-answer/README.md` and
|
||||
`docs/features/walk-cycles/README.md`.
|
||||
- **Workload, corpus/input hashes, open files, cursor, capabilities:**
|
||||
OpenTitan `0098135264` with its three known modified files,
|
||||
`git status --porcelain` checked after every phase. `bench.py scanwait`,
|
||||
`lucisv.index.scope: "workspace"`, one open buffer (`sites.TB`), the `aes #(`
|
||||
cursor. `--verbose`, so the traced session is the one that answered.
|
||||
- **Machine, profile, load, competing activity:** M1 Max, macOS 27.0, release,
|
||||
default worker count. One-minute load 2.4–4.6 across both phases. No cargo
|
||||
command during a timed run.
|
||||
- **Commands, cache state, trial ordering, fresh sessions:**
|
||||
`tools/guard.sh -m 8 -t 1800 -- python3 tools/perf/bench.py scanwait
|
||||
--server … --tries 3`, `SPLIT` then `R2A`, three fresh processes per cell,
|
||||
cold and warm store per cell.
|
||||
- **Results:** `discovery` warm **165.56 → 154.90 ms**, cold
|
||||
**186.59 → 179.95**; `cap` warm **6.92 → 0.10**, cold **7.53 → 0.49**;
|
||||
`stats` **3 979 → 0** in both. First useful answer, three sessions each:
|
||||
cold 273.1/260.9/258.0 → 263.3/257.3/256.1; warm 281.3/300.8/282.8 →
|
||||
271.1/294.8/290.9 — **inside the spread, both ways**. The split itself
|
||||
attributes warm discovery as `walk` 158.01, `cap` 6.92, `sort` 0.52,
|
||||
`config` 0.00, `filelist` 0.00, `buffers` 0.00.
|
||||
- **Result parity:** result count 1 in every session; the persistent store
|
||||
byte-identical to the reference's (sha256 `1f7799db4885dc8d…`, 46 486 433
|
||||
bytes).
|
||||
- **Memory:** unchanged by construction (no retention moved); measured with
|
||||
R2b below.
|
||||
- **Guard outcome:** no kill.
|
||||
- **Decision:** **retained**, as a tidy-up rather than a fix — 3 976 syscalls
|
||||
for a number already in hand is work with no defence, and it costs nothing.
|
||||
The first answer is not what it moved. The finding that mattered is that
|
||||
`walk` is 95 % of discovery, which is what sent §61.3 at the *order* of the
|
||||
scan (R2b) rather than at the walk.
|
||||
|
||||
## Experiment record — R2b-2026-09-08 (stage R2b)
|
||||
|
||||
- **Experiment ID / stage / date / owner:** `R2b-2026-09-08` / R2b (TODO §61.3)
|
||||
/ 2026-09-08, America/Chicago / dev agent (Opus).
|
||||
- **Hypothesis and exact expected work reduction:** hand the raised-folder work
|
||||
to the scan before the remaining discovery finishes — one coherent scan, the
|
||||
folder walked, stepped and published first. Expected: the first useful answer
|
||||
≈ folder walk + store open + the folder's own steps, i.e. the 155 ms
|
||||
workspace walk out from in front of it.
|
||||
- **Reference commit, candidate commit or diff hash, binary hashes:** reference
|
||||
trunk `a1c77c053fd940db4e8ac3b112aff1ef3d3d7235`, sha256
|
||||
`827c7ac222c829d1…`. Candidate `R2` = that tree + the whole §61.3 diff,
|
||||
sha256 `3db0c799a8302696…`. Release, `rustc 1.97.1 (Homebrew)`.
|
||||
- **Files changed / API contracts amended / topology references:**
|
||||
`lucisv_core/src/walk.rs` (`collect_files_below`, additive),
|
||||
`lucisv_server/src/state/{discover.rs (new), mod.rs, scan.rs}`,
|
||||
`scan_trace.rs`, `server/{index.rs, startup.rs}`, `server/tests/startup.rs`,
|
||||
`tools/perf/phases_p4.py`. Amended in their own READMEs, rules unchanged:
|
||||
index-scope, scan-interleave, indexing-ux, index-persistence, walk-cycles.
|
||||
Requests for the lead are listed in
|
||||
`docs/features/perf5r-first-answer/README.md`.
|
||||
- **Workload, corpus/input hashes, open files, cursor, capabilities:**
|
||||
OpenTitan `0098135264`, three known modified files, `git status --porcelain`
|
||||
checked after every phase. Phases `scanwait`, `scan`, `scanprofile`,
|
||||
`scanserve`, `rss`, `didopen`, `scopes`; `sites.TB` open, the `aes #(`
|
||||
cursor; 0 / 1 / 10 / 100 buffer cells.
|
||||
- **Machine, profile, load, competing activity:** M1 Max, macOS 27.0, release.
|
||||
Load 1.8–4.2, except the first `scanprofile` pair which ran into a
|
||||
`syspolicyd` burst at 8.6 and was re-run in the quiet window — **both runs
|
||||
quoted**. No cargo command during a timed run.
|
||||
- **Commands, cache state, trial ordering, fresh sessions:**
|
||||
`tools/guard.sh -m 8 -t 1800 -- python3 tools/perf/bench.py <phase>
|
||||
--tries 3`, `REF` then `R2` per phase, `didopen` re-run
|
||||
R2/REF/R2/REF alternating. Three fresh processes per cell.
|
||||
- **Results — first / repeat / range (ms, three fresh sessions):**
|
||||
|
||||
| cell | `REF` | `R2` | paired |
|
||||
|---|---|---|---|
|
||||
| `scanwait` cold, first useful answer | 272.1 / 265.9 / 265.1 | 83.9 / 77.9 / 77.2 | **−70.7 %** |
|
||||
| `scanwait` warm, first useful answer | 300.6 / 301.3 / 303.4 | 113.4 / 115.1 / 115.5 | **−61.8 %** |
|
||||
| `scan` cold, first useful answer | 261.3 / 260.7 / 262.7 | 78.8 / 83.2 / 81.5 | **−68.8 %** |
|
||||
| `scan` warm, first useful answer | 280.8 / 284.7 / 281.6 | 114.2 / 115.0 / 116.2 | **−59.2 %** |
|
||||
| `scan` workspace, cold settled | 2 716.8 / 2 785.9 / 2 740.0 | 2 703.3 / 2 704.1 / 2 733.1 | −1.3 % |
|
||||
| `scan` workspace, warm settled | 1 045.3 / 999.4 / 1 034.0 | 995.4 / 997.4 / 1 026.5 | −3.5 % |
|
||||
| `scanprofile` warm, 0 / 1 / 10 / 100 buffers | 1 046.2 / 1 013.7 / 1 020.0 / 1 231.6 | 991.9 / 1 038.6 / 1 069.3 / 1 169.0 | −5.2 / **+2.5** / **+4.8** / −5.1 % |
|
||||
|
||||
- **Work counts:** `read` 3 976 in every workspace cell of both binaries;
|
||||
`stats` 0; `walk_dirs` 2 (one folder, one root). Traced `scanwait`:
|
||||
`discovery` 182.8 → 155.9 warm and 188.4 → 160.3 cold, `cache_open`
|
||||
89.7 → 88.9, **`first_publish` 274.7 → 92.0 warm and 192.0 → 5.7 cold**.
|
||||
- **Result parity:** result count **1 in 12 of 12** sessions, both binaries.
|
||||
`scopes` 24 of 24 result counts equal. `scanserve` `mismatched_answers` 0 and
|
||||
`unsettled_answers` (new: every answer, empty ones included, equal to the
|
||||
settled one) **0** for both binaries, cold and warm, over 54 mid-scan
|
||||
requests. **The persistent store is byte-identical**: 28 stores over seven
|
||||
phases and both binaries reduce to three sha256s —
|
||||
workspace `1f7799db4885dc8d…` (46 486 433 B), default `fea51578039cf937…`
|
||||
(1 615 179 B), depth 0 `d5e641a24188960e…` (6 833 B).
|
||||
- **Peak and idle memory:** idle RSS cold **549 184 → 501 840 KiB (−8.6 %)**,
|
||||
warm **429 936 → 426 752 (−0.7 %)**; peak equals idle in all 12 sessions of
|
||||
both binaries, as in every round since §P4a.
|
||||
- **Guard outcome:** no kill, `-m 8 -t 1800` throughout.
|
||||
- **Correctness checks:** eight new wire tests over the ordering matrix
|
||||
(configuration before/after `didOpen`, late/no reply, unsaved buffer, two
|
||||
buffers in two folders, root-level file, a dependency outside the first
|
||||
folder, the bar's denominator, the opening bound) plus the four existing
|
||||
§P4b2/§P4b3 startup tests — 24 startup tests green. Seven new
|
||||
`lucisv_core::walk` tests, including three that assert
|
||||
`collect_files_below` equals the whole-root walk restricted to that subtree.
|
||||
Workspace suite 4 343 → **4 360**, none dropped; `cargo fmt` clean, guarded
|
||||
`cargo clippy --all-targets` clean.
|
||||
- **Decision:** **retained.** Gates: ≤ 200 ms first definition met cold and
|
||||
warm with a wide margin; warm quiet settle ≤ 1 s met for the first time
|
||||
(997 ms, by less than the run-to-run spread); RSS kept; store bytes
|
||||
identical; scope cells identical; coherence 0/0. Two things named rather than
|
||||
hidden: the settled scan is **+2.5 % / +4.8 % with 1 / 10 open buffers**
|
||||
because the neighbourhood subtree is walked twice, and the "every first
|
||||
definition equals the settled target" gate is met on the measured cursor and
|
||||
on all 54 probe requests but is **not true by construction** for a
|
||||
cross-folder cursor — pinned by a test, argued in the feature README, and
|
||||
filed as a `server/dispatch.rs` handshake.
|
||||
|
||||
## Experiment record — R1b-2026-09-08 (stage R1b)
|
||||
|
||||
- **Experiment ID / stage / date / owner:** `R1b-2026-09-08` / R1b (TODO
|
||||
|
||||
+3
-3
@@ -136,7 +136,7 @@ what a change on the pointed-to side must not silently break.
|
||||
| `lucisv ──▶ vlog_linter` | depends | The public linter API for `lucisv check` — `lint` + `LintContext`/`ParsedSource`, `apply_fixes`, `select_rules` (the CLI does not call `run` itself). Relies on: rule names stable, linting never panics/writes, findings sorted by `(span.start, span.end, rule)`. `package_exports_in(path, file, tokens, src)` (perf5-p3: the CLI census hands the linter its one `ParsedSource` for the package half as it already did for `module_interfaces`; the text form is a wrapper; an AST gate spares files that declare no package from the one-file index). |
|
||||
| `lucisv ──▶ vlog_parser` | depends | `LineIndex` / `TextRange` for lint report coordinates, plus `PARSE_STACK_SIZE` for both the named `lucisv` thread and rayon workers. (The CLI otherwise reaches the parser through the formatter and linter.) |
|
||||
| `lucisv ──▶ rayon` | depends | The worker pool. Pinned exactly; pool must keep `stack_size(vlog_parser::PARSE_STACK_SIZE)` (currently 16 MiB; recursion-limit handshake) or the parser's depth guarantee regresses to a stack overflow. |
|
||||
| `lucisv_server ──▶ lucisv_core` | depends | Same config discovery and walk as the CLI (that sameness is the point — format-on-save must agree with `lucisv --check`), `filelist::read` (index scope rung 1, `+incdir+` for the include graph), `cache::content_hash` (re-used by the persistent index cache — one FNV-1a, not two). |
|
||||
| `lucisv_server ──▶ lucisv_core` | depends | Same config discovery and walk as the CLI (that sameness is the point — format-on-save must agree with `lucisv --check`), `filelist::read` (index scope rung 1, `+incdir+` for the include graph), `cache::content_hash` (re-used by the persistent index cache — one FNV-1a, not two). `walk::collect_files_with` (each walked file with the length the walk's own `metadata` call already holds; `None` for an input named rather than walked) and `walk::collect_files_below(root, input, …)` (a subtree walk that carries the ancestor `.gitignore`/`--exclude` stack down and yields nothing when an ancestor the root walk would not enter blocks it) — perf5r-first-answer, 2026-09-08; `collect_files` is unchanged and a wrapper. |
|
||||
| `lucisv_server ──▶ vlog_parser` | depends | `tokenize`, `parse_source_tolerant`/`parse_tolerant`, `ParseDiagnostic`, `LineIndex`, `TextRange`, tokens + trivia, `defines`, `KEYWORDS` (completion keyword tier; also the source the hand-maintained VS Code grammar is test-locked to), `PARSE_STACK_SIZE` for the named `lucisv-main` thread, and `stats::parses()` (perf5-p1: a per-thread whole-file parse count, asserted by the code-action tests — a repeated offer on an unchanged buffer parses nothing). |
|
||||
| `lucisv_server ──▶ vlog_semantic` | depends | `analyze`/`Semantics` (every navigation answer), `WorkspaceIndex` (build/incremental update, units/members/defines, `instantiations_of`/`subclasses_of` edge tables, `FileFacts` codec for the persistent cache), `resolve_external` overlay, `index_order`/`IndexBuilder` (watched builds), and `files_mentioning` as a refactoring selector rung (perf5-p2, handshake 33: `module_select::hierarchical_users` — previously the semantic lints' oracle only), and `WorkspaceIndex::table_sizes() -> IndexTableSizes` (perf5-p4: a read-only walk over the tables for the scan trace's memory line — end of scan only, never on a request path; no codec change). |
|
||||
| `lucisv_server ◀──▶ vlog_semantic` | handshake | Two negotiated additions, both 2026-08-28 and both additive: **`Symbol::detail_span` / `Def::detail_span`** (where a non-ANSI port's body declaration completes the header that names it — the server's hover card and `nav::definition` both read it, and they show/jump to it in the same order), and **`Semantics::symbols_named`** (name → declarations, built in `analyze`, in declaration order — the server replaced two scan-every-symbol loops with it and the *first-match tie-break must stay declaration order* or hover's choice between two live declarations of one name changes). `docs/features/port-detail-spans/README.md`. |
|
||||
@@ -555,7 +555,7 @@ promise:
|
||||
| `dut-hierarchy ──▶ vscode-hierarchy-sidebar` | depends | TODO §56 (2026-09-06): `hierarchySections.js` consumes the sidebar's model (`rootNode`, the reverse instance index memoised on the model) and its webview renderer's row menu; no edge to any Rust crate — the server is untouched. |
|
||||
| `coverage-gaps-l` (TODO §54, 0.49.0) | lane | Touches `vlog_parser` (ast + parser + the `randsequence` keyword in the token table), `vlog_formatter` (arms, `[format] uvm-utils-indent`), `vlog_semantic` (bind arms), `vlog_linter`, `vlog_refactor` (match arms), `lucisv_core` (the config key), `lucisv_server` (settings, format) and `editors/vscode` (the setting, the regenerated grammar). New AST: `StmtKind::{EventTrigger, Let, RandSequence}`, `ExprKind::StreamWith`, `DataDecl::strength`, `ClockingSkew`; `size_pins` unmoved. |
|
||||
| `hover-line-index ──▶ port-detail-spans / index-persistence` | depends + handshake | `DeclLines { name, detail }` rides each indexed `Decl`, so ordinary and split-port hover headings do not reread a file just to compute a line. The record grew again and **`FACTS_FORMAT` went 3 → 4**; the server's bounded `FileView` cache supplies the text/`LineIndex` only when a snippet or a non-indexed position still needs it. Its four invalidation points are `set_document`, `close_document`, `update_one`, and a whole rebuild. |
|
||||
| `scan-interleave ◀──▶ workspace-index` | handshake | A scan is a stepped `Scan` value; staged `FileFacts` land through `WorkspaceIndex::absorb`, one whole-index merge per queue drain rather than per file. `Candidates::absorb` and (until perf5-p4, `IncludeGraph::absorb`; since 2026-09-08 the graph is rebuilt from each file's staged include list, `IncludeGraph::from_includes`, read in the file's own step) publish their tables in the same drain, so “the workspace as far as scanned” cannot mean three different prefixes. **Amended by perf5-p4 (2026-09-08):** the startup is staged behind the `workspace/configuration` answer with a 2 s bound (`server/startup.rs`), so there is one startup scan at the answered scope and no empty default-scope scan; the scan reads each file's text in its own step (`Scan::take_text`, never the whole corpus up front) and orders the work list open buffers → their raised folders → the rest (`scan_order.rs`); `must_wait` gains `staging` and `head_owed` — a held opening request is answered inside the startup scan once the buffers' folder head is published, never off a one-file prefix; the store is opened at the first step that needs it and not rewritten when it was loaded canonical and nothing was appended (`index_cache.rs::already_compact`); `state.rs` is now `state/mod.rs` + `state/scan.rs` (a pure move). The rescan order contract (decision 2) is unchanged. |
|
||||
| `scan-interleave ◀──▶ workspace-index` | handshake | A scan is a stepped `Scan` value; staged `FileFacts` land through `WorkspaceIndex::absorb`, one whole-index merge per queue drain rather than per file. `Candidates::absorb` and (until perf5-p4, `IncludeGraph::absorb`; since 2026-09-08 the graph is rebuilt from each file's staged include list, `IncludeGraph::from_includes`, read in the file's own step) publish their tables in the same drain, so “the workspace as far as scanned” cannot mean three different prefixes. **Amended by perf5-p4 (2026-09-08):** the startup is staged behind the `workspace/configuration` answer with a 2 s bound (`server/startup.rs`), so there is one startup scan at the answered scope and no empty default-scope scan (perf5r-first-answer, 2026-09-08: plus `OPENING_FILE_WAIT`, 25 ms inside that window, spent only by a workspace session whose opening burst holds no `didOpen`; and the scan is discovered in two phases when it pays — the open buffers' raised folders walked, stepped and published first, the rest of the scope walked as a zero-file step afterwards, `state/discover.rs::first_scope` + `PendingDiscovery`; bounded to rung 2, a raised folder that is a strict descendant of a root, at most `HEAD_WALK_MAX` = 512 files, and the session's first scan — otherwise today's single walk); the scan reads each file's text in its own step (`Scan::take_text`, never the whole corpus up front) and orders the work list open buffers → their raised folders → the rest (`scan_order.rs`); `must_wait` gains `staging` and `head_owed` — a held opening request is answered inside the startup scan once the buffers' folder head is published, never off a one-file prefix; the store is opened at the first step that needs it and not rewritten when it was loaded canonical and nothing was appended (`index_cache.rs::already_compact`); `state.rs` is now `state/mod.rs` + `state/scan.rs` (a pure move). The rescan order contract (decision 2) is unchanged. |
|
||||
| `scan-interleave ──▶ hover-line-index` | depends | Delivers hover-line-index's measured startup-wait request: a startup scan above 64 files drains queued messages between files. A rescan deliberately still holds requests; what an answer sees never depends on elapsed wall time. |
|
||||
| `index-scope ──▶ scan-interleave` | depends | A scope widen is the second `Scan` shape (`begin_widen`) and shares `scan_step`/`finish_scan`; it folds only newly reached folders plus open-buffer analyses, never masquerades as a whole scan, and never interleaves. Folder scope now ships at depth 2; rootless sessions do not climb an unnamed tree. |
|
||||
| `index-scope ──▶ one-parse / completion-core` | depends | Whole scans and widens reuse each open `Document`'s existing `FileFacts` and completion words rather than reparse its text. `IndexEvent::Analyzed` keeps this distinct from a persistent-cache hit. |
|
||||
@@ -716,7 +716,7 @@ untouched, reusing existing arms.
|
||||
| `vlog_refactor` | refactor (plan), refactor-rename (including `prepare_rename_here` / `rename_name_at` selector half), refactor-ports (including module-target selectors), refactor-instantiate, references-nav (whole-scope equivalence oracle), and the refactor half of decomposition-semantic; expand-wildcard and convert-to-ansi (`ports/`), organize-imports (`imports.rs`), extract-inline-module (`extract/`, `inline/`, `check/ledger.rs`) |
|
||||
| `lucisv_core` | lucisv-core-lift (`config.rs`, `walk.rs`), filelist (`filelist.rs`), format-cache (`cache.rs`) |
|
||||
| `lucisv` (CLI) | cli-polish, config-discovery (wiring), parallel-files, cli-filelist, linter-core (CLI half in `lint.rs`), one-parse (`lint.rs` parses once via `ParsedSource`), format-cache (wiring), release-prep (`--version` contract) |
|
||||
| `lucisv_server` | lucisv-server (trunk), decomposition-server (`server/`, `completion/`), and one or two modules per capability feature: editor-scopes→`pairs.rs`, filelist→scope ladder in `state.rs`, include-nav→`includes.rs`, completion-core/fuzzy-completion/member-completion→`completion/`+`candidates.rs`, completion-templates→`templates.rs`, inline-templates→`inline.rs`, inline-instantiation→`inline.rs`+`completion/`+`candidates.rs` (+`settings.rs` key), bind-semantics→`instantiate.rs`, macro-expansion→`expand.rs`, hierarchy→`hierarchy.rs`, vscode-hierarchy-sidebar→`design_hierarchy.rs`, type-hierarchy→`type_hierarchy.rs`, type-definition→`type_def.rs`, code-lens→`lens.rs`, inlay-hints→`inlay.rs`, server-lint→`lint.rs`+`lint/project.rs`+`code_action.rs`, one-parse→`lint.rs`+`state.rs` (`Document.tree`), refactor wiring/performance fan-outs→`rename.rs`/`ports.rs`+`state.rs`, apply-edit+folders-and-config+cancel-request+work-done-progress→`server/`, editor-settings+indexing-ux+index-scope+index-persistence→`settings.rs`+`state.rs`(+`index_cache.rs`), incremental-sync→`sync.rs`, file-watching→`watch.rs`, file-operations→`file_ops.rs` (+`include_sources` in `state.rs`), pull-diagnostics→`diagnostics.rs`+`server/`, semantic-tokens-delta→`tokens.rs`+`server/semantic_tokens.rs`, on-type-formatting→`on_type.rs`, will-save-wait-until→`format.rs` (+`settings.rs`/`main.rs`), selection-range→`selection.rs`, linked-editing→`linked.rs`, references-nav (server half)→`folding.rs`+`nav.rs`, large-file-mode→`large.rs`+`server/large_file.rs`, lsp-318-extras→`format.rs` (+`main.rs` capability), hover-declarations→`hover.rs`(+`nav.rs`), port-detail-spans (server half)→`hover.rs`+`nav.rs`, hover-line-index→`hover.rs`+`locate.rs`+`state.rs`, scan-interleave/change-debounce/verbose-timing→`server/`+`state.rs`, perf5-p1→`fences.rs` (+ the `_at` helpers in `ports.rs`/`imports.rs`/`extract.rs`/`inline_module.rs`), perf5-p2→`rename_trace.rs`+`module_select.rs`, perf5-p4→`scan_trace.rs`+`scan_order.rs`+`server/startup.rs`+`state/scan.rs` (+ counters and the compaction skip in `index_cache.rs`), perf measurements→`src/perf.rs` (`docs/perf/README.md`, not a feature README), interactive-latency→`state.rs` (the two token searches) + `selection.rs`/`on_type.rs`/`completion/`/`inline.rs` (their callers) + `src/perf.rs`/`tests/e2e.rs` (its measurements), editor-packaging (grammar test)→`tests/grammar.rs` |
|
||||
| `lucisv_server` | lucisv-server (trunk), decomposition-server (`server/`, `completion/`), and one or two modules per capability feature: editor-scopes→`pairs.rs`, filelist→scope ladder in `state.rs`, include-nav→`includes.rs`, completion-core/fuzzy-completion/member-completion→`completion/`+`candidates.rs`, completion-templates→`templates.rs`, inline-templates→`inline.rs`, inline-instantiation→`inline.rs`+`completion/`+`candidates.rs` (+`settings.rs` key), bind-semantics→`instantiate.rs`, macro-expansion→`expand.rs`, hierarchy→`hierarchy.rs`, vscode-hierarchy-sidebar→`design_hierarchy.rs`, type-hierarchy→`type_hierarchy.rs`, type-definition→`type_def.rs`, code-lens→`lens.rs`, inlay-hints→`inlay.rs`, server-lint→`lint.rs`+`lint/project.rs`+`code_action.rs`, one-parse→`lint.rs`+`state.rs` (`Document.tree`), refactor wiring/performance fan-outs→`rename.rs`/`ports.rs`+`state.rs`, apply-edit+folders-and-config+cancel-request+work-done-progress→`server/`, editor-settings+indexing-ux+index-scope+index-persistence→`settings.rs`+`state.rs`(+`index_cache.rs`), incremental-sync→`sync.rs`, file-watching→`watch.rs`, file-operations→`file_ops.rs` (+`include_sources` in `state.rs`), pull-diagnostics→`diagnostics.rs`+`server/`, semantic-tokens-delta→`tokens.rs`+`server/semantic_tokens.rs`, on-type-formatting→`on_type.rs`, will-save-wait-until→`format.rs` (+`settings.rs`/`main.rs`), selection-range→`selection.rs`, linked-editing→`linked.rs`, references-nav (server half)→`folding.rs`+`nav.rs`, large-file-mode→`large.rs`+`server/large_file.rs`, lsp-318-extras→`format.rs` (+`main.rs` capability), hover-declarations→`hover.rs`(+`nav.rs`), port-detail-spans (server half)→`hover.rs`+`nav.rs`, hover-line-index→`hover.rs`+`locate.rs`+`state.rs`, scan-interleave/change-debounce/verbose-timing→`server/`+`state.rs`, perf5-p1→`fences.rs` (+ the `_at` helpers in `ports.rs`/`imports.rs`/`extract.rs`/`inline_module.rs`), perf5-p2→`rename_trace.rs`+`module_select.rs`, perf5-p4→`scan_trace.rs`+`scan_order.rs`+`server/startup.rs`+`state/scan.rs`, perf5r-first-answer→`state/discover.rs` (+ counters and the compaction skip in `index_cache.rs`), perf measurements→`src/perf.rs` (`docs/perf/README.md`, not a feature README), interactive-latency→`state.rs` (the two token searches) + `selection.rs`/`on_type.rs`/`completion/`/`inline.rs` (their callers) + `src/perf.rs`/`tests/e2e.rs` (its measurements), editor-packaging (grammar test)→`tests/grammar.rs` |
|
||||
| `editors/vscode` | editor-packaging, editor-snippets, editor-settings (manifest half), editor-scopes (rainbow half), vscode-hierarchy-sidebar (`hierarchyView.js`/`hierarchyModel.js`), dut-hierarchy (`hierarchySections.js`), extract-inline-module (`extract.js`), editor-platform-vsix, editor-marketplace-page, index-persistence (`storagePath` line), verbose-timing (`lucisv.verbose`, spawn args and restart in `extension.js`) |
|
||||
| `tools/` + CI | corpus-check, release-prep, ci-release, editor-platform-vsix (staging), range-formatting (`lucisv-changed.sh`) |
|
||||
|
||||
|
||||
+18
-7
@@ -230,14 +230,22 @@ def scan_chatter(s):
|
||||
def phase_scanserve():
|
||||
"""A definition every 200 ms for as long as the scan runs.
|
||||
|
||||
Two questions: what those requests cost while the index is being built,
|
||||
and whether any of them saw a table the finished index disagrees with. The
|
||||
coherence check is what a client can actually observe — a mid-scan answer
|
||||
may be *empty* (the file it would name has not been reached), but it may
|
||||
never name somewhere else than the settled index does.
|
||||
Three questions: what those requests cost while the index is being built,
|
||||
whether any of them saw a table the finished index disagrees with, and how
|
||||
many were not yet the settled answer at all.
|
||||
|
||||
**Two counters, because they are two contracts.** `mismatched_answers` is
|
||||
the coherence contract of `docs/features/index-scope/README.md`: a mid-scan
|
||||
answer may be *empty* — the file it would name has not been reached — but
|
||||
it may never name somewhere else than the settled index does. That is the
|
||||
number the 0.51.0 baseline cells were taken with and the one they stay
|
||||
comparable against. `unsettled_answers` is the review §2 gate (TODO §61.3):
|
||||
every answer, empty ones included, equal to the settled one. An empty
|
||||
interim answer is coherent and useless, and the gate is about useful.
|
||||
"""
|
||||
for cache in ("cold", "warm"):
|
||||
during, results, mismatched, settled = [], [], 0, []
|
||||
unsettled = 0
|
||||
for _ in range(ARGS.tries):
|
||||
with session("workspace", cold=(cache == "cold"), verbose=True,
|
||||
storage_name="p4-serve") as s:
|
||||
@@ -266,15 +274,18 @@ def phase_scanserve():
|
||||
results.append(len(seen))
|
||||
mismatched += sum(1 for answer in seen
|
||||
if answer and answer != settled_answer)
|
||||
unsettled += sum(1 for answer in seen if answer != settled_answer)
|
||||
during.sort()
|
||||
record(phase="scanserve", row="definition every 200 ms during a %s scan" % cache,
|
||||
ms=during, fresh_process=True, result_count=len(during),
|
||||
requests_per_session=results, mismatched_answers=mismatched,
|
||||
settled_ms=settled,
|
||||
unsettled_answers=unsettled, settled_ms=settled,
|
||||
status="ok" if mismatched == 0 else "error",
|
||||
message=None if mismatched == 0 else
|
||||
"%d mid-scan answers disagreed with the settled index" % mismatched,
|
||||
note="ms is every mid-scan definition, sorted, across all tries; "
|
||||
"`mismatched_answers` counts non-empty answers that named "
|
||||
"somewhere the settled index does not — the coherence "
|
||||
"contract of docs/features/index-scope/README.md")
|
||||
"contract of docs/features/index-scope/README.md; "
|
||||
"`unsettled_answers` counts every answer that was not the "
|
||||
"settled one, empty ones included — the review §2 gate")
|
||||
Reference in new issue
Block a user