Any way to optimize loops or raycasts at all?

I have the typical custom renderer, but with shading and shadows and all the extra raycasts I have to do really bogs down the fps unless I’m looking straight up. That isn’t really the issue, I’m just wandering if there’s any optimizing I can do at all, involving loops or raycasts. Like would putting the tiles in a script table help? Is :GetChildren() laggier than using tables? Any better ways to set properties?

Parallel Lua ought to help

So started reading the parallel lua document, but does this mean I have to use multiple scripts? Or multiple actors?

Multiple actors with scripts inside them

From the docs

This doesn’t mean you should use as many Actors as possible. You should still divide code into Actors based on logic units rather than breaking code with connected logic to different Actors.

For example, if you want to enable raycasting validation in parallel, it’s reasonable to use 64 Actors and more instead of just 4, even if you’re targeting 4-core systems. This is valuable for scalability of the system and allows it to distribute the work based on the capability of the underlying hardware. However, you also shouldn’t use too many Actors, which are hard to maintain.

Well that’d be kinda weird/complicated since I just run all of the rendering code in the same script, I don’t know how to, or why to split it up, and even communicate the scripts without causing a lot of lag.

Actor has a messaging api along with SharedTables which may be useful in your case

How many rays are you casting per second? You can boost performance by running them in parallel than in series i.e one after the other. For eg, if you raycast 64 times, you can either have 64 actors with scripts to raycast OR have 32 actors with scripts that raycast twice, It’s hard to give an example without knowing how your rendered works

1 Like

Well right now I’m using a 75x75 grid of tiles that each raycast, so that would be 5,625. However the framerate is probably around 30 or 60, but it fluctuates a lot, but we can go with 30 fps for now, so that’d be 168,750 (wow) raycasts every second.

Oh yeah I also forgot to mention, I’m trying the parallel lua, and I keep having to do task.synchronize and task.desynchronize to fix the errors that I’m getting. Like even FilterDescendantsInstances is not safe to modify in parallel bruh it keeps complaining about everything

Yea it’s annoying but unfortunately there are specific stuff that parallel luau has read/write/read and write access to. I think Thread Safety covers that

That is a very large frequency of raycasts. I think that you should try to avoid this all together if you can. Parallel processing would definitely help to improve performance, but maybe there is a better solution out there that does not require ~170k raycasts per second.

Well what else can I do? Raycasting is the perfect option but it’s just laggy. I don’t see any other alternative, unless you can.