BlueJellyCat How do you know the code you posted is the bottleneck? Maybe the problem is in the caller, or somewhere entirely else. Hard to tell without seeing the whole thing. But I'm not sure doing stuff to the tilemap while you're performing the search is actually a good idea.
Launching a thread is simple:
var thread = Thread.new()
thread.start(self, "worker_function")
Read up more on threads in Godot in the documentation. If you don't have any previous experience with concurrent programming, search for some online resources that explain the basic conecpts. They are the same in any programming language.