fzy icon indicating copy to clipboard operation
fzy copied to clipboard

PreparedHaystack could improve speed of sequential searches

Open hugopl opened this issue 2 years ago • 0 comments

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:

  • PreparedHaystack could 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.

hugopl avatar Jun 22 '23 19:06 hugopl