fzy
fzy copied to clipboard
PreparedHaystack could improve speed of sequential searches
I'll write this down here so I don't forget.
Using the usual metaphor of needle and haystack.
For the same haystack, the search results for abcd wil be a subset of the results for abc.
Generalizing, if the previous needle matches the next needle, then the next results will be a subset of the previous results.
So, we can avoid searching through the entire haystack. This is a very common use case (at least for my own uses of this shard 😅),
To accomplish this:
PreparedHaystackcould store the last set of matches returned and re-use it in the last search.- if the previous search term matches the new search term, then do the search only on previous results, since the new result will be for sure a subset of the previous result.