Repository navigation
Several performance improvements - #49
Merged
Merged
Conversation
`does_file_match_query` had two bugs when using the `PrescanMemmem` search method: 1. `full.extend(buf)` always appended the full 2048-byte buffer regardless of how many bytes `file.read()` actually returned. On the last read of a file (or any short read), this fed stale bytes from a previous iteration into the search buffer, which could produce false negatives — causing the prescan to incorrectly skip files that contain the query. 2. The overlap logic between chunks split on newlines, which has nothing to do with ensuring cross-chunk matches are found. The correct approach is to retain exactly `query.len() - 1` bytes of overlap, so a match that starts near the end of one chunk and ends in the next is never missed.
`search_file_line_by_line` used the default 8 KB `BufReader` buffer, which means a syscall roughly every 8 KB when scanning large files. Increasing the buffer to 64 KB reduces the number of `read` syscalls by up to 8x on large files with no change in behavior.
`memmem::Finder::new` preprocesses the needle into an internal search table. Previously it was called inside `does_file_match_query`, rebuilding that table on every file scanned. This moves the construction into the outer closure of `build_parallel().run()`, so the `Finder` is built once per walk thread and reused for every file on that thread. For a search over thousands of files, this reduces `Finder::new` calls from O(files) to O(threads).
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.
This implements several smaller performance improvements. The biggest of which is increasing the number of default threads.
FinderonceStats
On a 4.0G codebase with no explicit threads and a cold cache on a M1 Macbook Pro.
Before:
After: