krisk / fuse-swift

A lightweight fuzzy-search library, with zero dependencies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Best practices around reusing `Fuse` objects?

wearhere opened this issue · comments

If I repeatedly search over similar datasets with the same parameters, I wonder if I should use the same Fuse object for all searches:

let fuse = Fuse()

func search() {
  return fuse.search...
}

vs. using a new Fuse object for every search

func search() {
  return Fuse().search...
}

Of particular concern to me is that I am using the async APIs which rely on per-instance dispatch queues. I kind of like the idea of using a new Fuse object for every search so that the searches don't "compete" on the same dispatch queue, but I don't know if there's actually any limit to concurrency per-custom-queue (as opposed to at the level of the global queues that back these custom queues, or eventually at the level where the work items are scheduled on threads, in which case different Fuse objects would be competing anyway).

I also don't know if there's overhead to having many custom dispatch queues, in which case it would be better to reuse one Fuse object. This Stack Overflow makes it seem like this wouldn't be a problem.