Ugh yeah I'm assuming that creating an instance each time will be slower than reusing a single instance based on intuition not data
Per thread, but yeah I was thinking it's based on the assumption that each coroutine will run sequentially in it's thread, but you're right that is the case in this scenario.
The other thing to mention is you're not including the cost of copying the data from the collision data to the clipped map, and then you could also compare that and not using a clipped map at all.
If you're really worried about performance, here's some other ways to optimise or to test if they perform better:
- Directions & distances arrays can be combined into one
- ringbufferX/Y can be combined into one
- The "max turns" can be included into the backtrace
- Remove the path array creation and reuse it/pass it in as a parameter
- Arrays.setAll can be replaced with keeping track of visited tiles (although scu argues that it's a cheap call, I see 1-5% performance increase from it, definitely an over-optimisation though)