Add benchmark-driven performance optimizations - #82
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Process walked files in bounded chunks so build_index no longer retains every file's per-trigram map before merging postings. This keeps file ID assignment deterministic while reducing peak memory on large repositories. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore LF endings after the index build batching change so the branch diff remains focused on the actual optimization. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add 2000-file and 5000-file index build cases so the benchmark exercises repositories large enough to cross the builder extraction batch boundary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Let the index_build benchmark binary run an isolated child build with --peak-memory so Windows runs can report peak working set for large repository cases. Keep normal Criterion timing mode as the default. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Collect only successfully extracted file trigram maps for each build batch instead of storing Option entries and flattening them later. This keeps file IDs deterministic while reducing batch memory overhead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Write files.bin entries directly to the buffered writer and pass path iterators into write_index_files. This avoids allocating a temporary Vec for each file entry and removes the intermediate path Vec in write_index_v2. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Encode posting entries into a reusable scratch buffer and write them in chunks instead of issuing one small write per posting. This reduces per-entry serialization overhead while preserving posting order and the on-disk format. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Write lookup entries to lookup.bin through a reusable scratch buffer while postings are serialized, avoiding retention of the full lookup entry vector for high-diversity indexes. Add a high-diversity index build benchmark and peak-memory probe to exercise this path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Collect build-time postings in a flat vector, sort by trigram and file id, and stream grouped postings directly to the on-disk writer. This avoids constructing a HashMap of per-trigram posting vectors for full index builds while preserving the existing snapshot writer path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Detect already sorted unique posting lists before sorting and deduplicating during mask-aware query execution. Add an on-disk common-literal query benchmark that exercises mmap posting decode and query execution against built indexes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update the workspace package version and lockfile package entries for the performance optimization release. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a benchmark suite around tgrep-core and applies several performance-oriented changes to trigram extraction, query execution, and index serialization. It mainly targets the core indexing/query pipeline, where tgrep spends most of its time when building indexes and evaluating searches.
Changes:
- Add Criterion benchmarks for trigram extraction, query execution, and index builds.
- Optimize OR-query execution, lowercase trigram extraction, and on-disk index writing to reduce work and memory usage.
- Bump the workspace/package version to
0.1.20and update the lockfile for new benchmark dependencies.
Show a summary per file
| File | Description |
|---|---|
tgrep-core/src/trigram.rs |
Optimizes merged trigram extraction by skipping lowercase-copy work when content has no ASCII uppercase bytes; adds matching tests. |
tgrep-core/src/query.rs |
Reworks OR execution to union sorted results incrementally and adds posting-list sort/dedup helpers plus tests. |
tgrep-core/src/ondisk.rs |
Splits file-entry validation/writing so files.bin entries can be streamed without temporary allocation; adds round-trip test coverage. |
tgrep-core/src/builder.rs |
Replaces full-build inverted-map construction with batched flat postings, then writes index files from sorted postings. |
tgrep-core/benches/trigram_extraction.rs |
Adds Criterion benchmarks for trigram extraction on lowercase and mixed-case corpora. |
tgrep-core/benches/query_execution.rs |
Adds Criterion benchmarks for AND/OR execution and on-disk literal query workloads. |
tgrep-core/benches/index_build.rs |
Adds Criterion benchmarks for index-build throughput and a Windows-only peak working set probe. |
tgrep-core/Cargo.toml |
Adds benchmark dependencies and registers the new benchmark targets. |
Cargo.toml |
Bumps the workspace version. |
Cargo.lock |
Records new benchmark-related dependencies and updated crate versions. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 9/10 changed files
- Comments generated: 3
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (1)
tgrep-core/benches/index_build.rs:150
format_mibis only called from the Windows-specific peak-memory path, so it becomes dead code on non-Windows builds and causes the bench target to failclippy -D warnings. This function should be gated the same way as its only caller.
fn format_mib(bytes: u64) -> f64 {
bytes as f64 / 1024.0 / 1024.0
}
- Files reviewed: 11/12 changed files
- Comments generated: 5
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Shengyu Fu <shengyfu@microsoft.com>
There was a problem hiding this comment.
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 11/12 changed files
- Comments generated: 4
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 12/13 changed files
- Comments generated: 3
Summary
HashMap<u32, Vec<PostingEntry>>construction with flat postings sorted/grouped for writingBenchmark highlights
Validation
cargo check --workspacecargo fmt --all -- --checkcargo test --workspacecargo clippy --workspace --benches -- -D warnings