I have a VERY tight loop that runs on the entire Roblox world every RenderStepped. It’s seriously tight and it’s lagging the game. I need it to be faster.
One of the bottlenecks are IsA checks to see which things are BaseParts. So I need a really fast way to check if something is a BasePart. Faster than IsA. My loop takes 2 or 3 milliseconds with no code in it except for an IsA check.
Any ideas? I’m going to try adding an extra lookup table to store BaseParts if I can’t make polling faster.
You might be able to use tags on the parts you are looking for. Just tag each basepart with a certain tag you are looking for and that should be faster I think.
I’m looking for every BasePart in workspace. Indiscriminately.
It’s a bit more complex than that because I’m not actually looping through workspace’s descendants (else a lookup table would be lots faster), but rather a lookup table mapping workspace instances to clone instances. There are more than BaseParts in there so that Humanoids display correctly and etc.
I’m essentially displaying Workspace in a viewport frame.
But can you not tag every basepart? I’ve never used tags before but I imagine that it should be possible to do that. Even if you instance new baseparts, I’m pretty sure you can still tag them.
If it’s lagging I’d assume it’s because you’re running an iterator with such a costly method :GetDescendants() 60 times per second…I don’t think optimizing how you determine if a part is a BasePart would help anything, unless I misunderstood your original post.
Why not store the returned value of :IsA once in a dictionary with the key being the part in the current iteration? That way you only have to call it once.
I ended up using a lookup table to store all BaseParts so I don’t have to do any checking. The BasePart lookup table gets populated when the clones are created, and only once.