Using parallel lua to speed up computations

It might have to do with how you’re using a BindableEvent to merge the data instead of a SharedTable, and note that you can also safely use Raycast inside parallel threads (jic telling you if you were only using parallel to calculate the distances)

But I personally think you should try optimizing this with something that’s called a “swarm module”

A staff member has made a guide on this if you’d like to read that: Optimizing Unit Targeting in Roblox with a Swarm Module but I’ll try to explain it myself to my best.

Basically, you have to put all of your parts and parts’ positions into a cell inside of a grid using tables, when you have to do the computations, you can do both the distance check and raycast on ONLY the nearby cells as we know that the other cells are likely too far away, and because the cells are just stored in a table, we can just get the nearby cells with a simple for loop

This’ll likely optimize your system better because you don’t have to run unnecessary computations on EVERY single part that exists

1 Like