So, In my game I need to remove parts based on how close they are to you, and enable SurfaceGui that is located in these parts based on how close you are to them. Currently, I have around 3-4K parts, where I index name, SurfaceGui and position (to calculate the magntude), making it around almost 10K calls every frame, while indexing SurfaceGui takes 0.001ms, and position + name around the same amount.
I am looking for a way to avoid creating this big amount of index calls or somehow else decrease the lag. Help much appreciated.
Nope, streaming enabled stops your gameplay if you move too fast, I never had a good experience with it. Also this question is not only about loading or de loading, it is about scanning thru tons of parts to interact with them, etc
Index calls usually shouldn’t a big problem when it comes to lag, it could be more closely related to removing the parts. You could try parallel lua for this, but if you need to set properties it still needs to be serial…
You could probably still use it though, for example to check the distances. Place your script in an actor and then you can use task.desynchronize() to change it to parallel, and task.synchronize() to change it back to serial.
Another thing I would suggest you could do is part pooling. It’s a system where instead of creating and deleting parts constantly, you have a “cache” of parts that are kept in workspace and CFramed in when necessary, which is much faster than constantly creating/deleting parts. A nice module that does this for you is PartCache (PartCache, for all your quick part-creation needs), it’s very performant and works perfectly. The only disadvantage I guess is that you need to keep those parts in memory constantly, but that shouldn’t be a massive issue.
If you’re instantiating 3-4k unique objects, you’re probably doing something wrong.
This alone is non-scalable and will pose problems for users on lower end hardware.
As for the scripting side, using async funcitons would probably be your best bet, but honestly you may want to revise the effect you’re looking to replicate and finding a different way to do it.
Just because you can update a couple thousand parts per second doesn’t mean you should. There’s probably some hack or cheat to achieve the same effect.
Can you show a video or image of what exactly you’re trying to achieve and explain a bit more? There may be a better solution.
Yeah, I am using already a part pooling module, also I appreciate your suggestion regarding parallel Lua. However I solved this issue by putting every Property and child that I index in to a table when creating a part. Since these properties are static and don’t change, it worked out pretty well and completely got rid of this lag, while keeping the same functionality as before.
By the way, I said it was indexing because microprofiler showed me that I had around 10K calls and each one took approx. 0.001ms~ with the label “Index”