crates/index: walks the project with the search/VFS rules (vendor as library), parses .php files from tree-sitter outlines on a worker pool off the engine lock, updates incrementally from disk and buffers through an updater thread, caps at 200,000 files, and answers fuzzy file, class and symbol queries (nucleo-matcher, MPL-2.0 as a separate crate). Engine: index.status, goto.file, goto.class, goto.symbol; events indexProgress and indexReady drained by the pump; the index starts on project.open and is cancelled on close. Tests: unit, incremental, property (random queries and sources), engine and TCP control tests, release timing on a generated 20k-file project (3.9-4.2 s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
3 KiB
Rust
78 lines
3 KiB
Rust
//! Index timing on a generated 20,000-file project. Ignored by default; run
|
|
//! `cargo test --release -p lutra-index --test perf -- --ignored --nocapture`.
|
|
|
|
#![allow(
|
|
clippy::unwrap_used,
|
|
clippy::expect_used,
|
|
clippy::indexing_slicing,
|
|
clippy::panic
|
|
)]
|
|
|
|
use std::time::Instant;
|
|
|
|
use lutra_index::{CancelToken, Index, Update, build, default_threads};
|
|
|
|
#[test]
|
|
#[ignore = "measurement; run in release"]
|
|
fn index_20k_files() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let project = lutra_testkit::generate_php_project(dir.path(), 20_000);
|
|
println!(
|
|
"generated: {} indexed files, {} PHP ({} vendor), {:.1} MB PHP, {} classes",
|
|
project.indexed_files,
|
|
project.php_files,
|
|
project.vendor_files,
|
|
project.php_bytes as f64 / 1e6,
|
|
project.classes
|
|
);
|
|
let threads = default_threads();
|
|
for round in 0..3 {
|
|
let index = std::sync::Mutex::new(Index::new());
|
|
let mut first_batch = None;
|
|
let started = Instant::now();
|
|
let first = std::sync::Mutex::new(&mut first_batch);
|
|
let summary = build(dir.path(), threads, &CancelToken::new(), &|u| {
|
|
if let Update::Files { files, .. } = u {
|
|
let mut first = first.lock().unwrap();
|
|
if first.is_none() {
|
|
**first = Some(started.elapsed());
|
|
}
|
|
let mut index = index.lock().unwrap();
|
|
for f in files {
|
|
index.insert(f);
|
|
}
|
|
}
|
|
});
|
|
let index = index.into_inner().unwrap();
|
|
assert_eq!(index.len(), project.indexed_files);
|
|
let time = |f: &dyn Fn() -> usize| {
|
|
let mut runs: Vec<f64> = (0..7)
|
|
.map(|_| {
|
|
let t = Instant::now();
|
|
assert!(f() > 0);
|
|
t.elapsed().as_secs_f64() * 1e3
|
|
})
|
|
.collect();
|
|
runs.sort_by(f64::total_cmp);
|
|
(runs[0], runs[3])
|
|
};
|
|
let class = time(&|| index.find_classes("Serv12", 50).len());
|
|
let symbol = time(&|| index.find_symbols("handle1", 50).len());
|
|
let member = time(&|| index.find_symbols("Service12::hand", 50).len());
|
|
let file = time(&|| index.find_files("wid12", 50).len());
|
|
println!(
|
|
"round {round}: {threads} workers, walk {:.0} ms, first batch {:.0} ms, total {:.0} ms, {} files, {} symbols, {} parsed ({:.1} MB)",
|
|
summary.walk.as_secs_f64() * 1e3,
|
|
first_batch.unwrap().as_secs_f64() * 1e3,
|
|
summary.elapsed.as_secs_f64() * 1e3,
|
|
summary.files,
|
|
summary.symbols,
|
|
summary.parsed,
|
|
summary.parsed_bytes as f64 / 1e6,
|
|
);
|
|
println!(
|
|
" queries (min / median of 7): goto.class {:.1} / {:.1} ms, goto.symbol {:.1} / {:.1} ms, Class::member {:.1} / {:.1} ms, goto.file {:.1} / {:.1} ms",
|
|
class.0, class.1, symbol.0, symbol.1, member.0, member.1, file.0, file.1
|
|
);
|
|
}
|
|
}
|