Performance improvements to fuzzysearch #1359
Merged
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.
Description
While working on the filesystem refactoring, I noticed the fuzzysearch implementation had a few things making it more expensive than it should be. For example, the score function was calculated inside the sort function. This will recompute the score function needlessly as values are compared multiple times.
I made some simple adjustments which fix this issue. There were also some synchronous calls to the file system, so I made the code asynchronous which speeds it up even more.
As a bonus, the fuzzy search will now also work better with tabs and newlines, instead of only spaces.
Here are some test results for a large project, where I search for "t", "te", "tes" and "test" respectively.
Before
2.480142417 seconds
2.406085875 seconds
6.783014 seconds
6.755943334 seconds
After
0.465098708 seconds
0.444613625 seconds
0.431536375 seconds
0.391247541 seconds
Note that these results are not ordered as the current implementation won't cancel a previous search when a new one is initiated. This is another issue and is out of scope of this PR (it'll probably be fixed in the file system PR)
Related Issues
None
Checklist