Repository navigation
perf: scan patch bytes directly for search - #10
Merged
Merged
Conversation
Search read every source line through its own reader and zeroed a 64 KiB buffer twice per line, so a search ran at about 80 MB/s: 9 s to the first match on the 711 MB Linux v6.0...v7.0 patch. Files without revealed context are now scanned in spool order with memchr::memmem through one reusable 1 MiB window. A raw occurrence counts only when it lies inside one source record, so signs, headers, paths and markers still never match. Files whose unified rows do not follow record order, and files with revealed context, keep the per-line path. The per-line path no longer zeroes its buffer for each line. Results are pinned by new tests that compare every search with a brute-force oracle over the frozen source order.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Search on large patches was slow. On the 711 MB Linux v6.0…v7.0 patch (76,872 files), a search from the top took about 9 s to show the first match. An F3 that wrapped around the patch also took about 9 s. The search ran off the input thread, so the UI stayed responsive. It scanned at only about 80 MB/s.
Cause
Domain::scanread every source line through its own reader. For each line,Literal::findresized a 64 KiB buffer withresize(_, 0), twice. In a profile of the search thread, 88% of samples were in__bzero. Every file also allocated a new 64 KiB read window and refilled it.Fix
memchr::memmemruns over one reusable 1 MiB window (storage::PatchScan), so neighbouring files share reads. A raw occurrence counts only when it lies entirely inside one source record's bytes. A galloping search over the span index finds that record. Signs, headers, paths, hunk function context and\ No newlinemarkers still never match.Projection::unified_follows_sourcechecks this. A patch that interleaves-/+lines inside one change block does not follow it. Such files, and files with revealed context, keep the per-line path. Files that do not bound the search only run this check when they contain a hit.Search semantics do not change: case-sensitive literal, overlapping matches, source text only, unified order, wrapping once. The 3.6 s refusal while the index loads is unchanged. Searching a partial index needs the
Search incompletereporting from SPEC.md, which is a separate change.Numbers
Release builds of main (b6f7c8c) and this branch. Apple Silicon Mac, 160×50 PTY, ambient load about 5–7 on 18 cores. Each run checked first that no other perf-video runs were active. Queries:
irq_bypass_unregister_consumer(Linux) andgetRustPlatform(Bun). Timing runs from the key write to the first synchronized frame that shows the result line.Search probe: after the index is ready,
g,/queryEnter, then F3 until the search wraps. 3 runs each:On both builds, every run showed the same sequence of matches and wrap states.
Single runs on this branch only:
Full navigation harness (
nav_harness.py … after), 3 runs per build, interleaved, all runs pooled (p50 / p95 / max, ms):j30/sjduring no-match searchNotes on the harness numbers:
j, sojis no longer measured while a search runs. On main, Esc cancelled the search in under 0.4 ms.Searching…frames.Tests
New
engine::tests::search_semanticstests compare every search with a brute-force oracle. The oracle lists every occurrence in frozen unified order, and the test checks forward and backward results from every row of every file, at and one byte after each match, and at both ends. Covered cases:+/-\ No newlinemarkersThese tests were written and passed against main first (36 s there, 6 s on this branch).
The
literalbuffer tests now check the buffer's length instead of its capacity.cargo fmt --check, both clippy runs,cargo test --release --locked --no-fail-fast -- --test-threads=1, and the embedded host checks all pass.cargo +1.88.0 check --locked --all-targetsandRUSTDOCFLAGS=-D warnings cargo doc --no-deps --document-private-itemsalso pass.