Resources to find server lag or computational lag, or whatever lag it may be

I have a script, as everyone here does have, and it lags whenever it runs. Its purpose is to make a table containing all the blocks in a given model, and do several iterations to found out which blocks are disconnected and destroy them.

It works great, but when it first runs, the computer/studio stops for a second before resuming. I thought it might be because :getchildren or :getconnectedparts() was taking a while to call, so I put in a tick() function to count how long it takes for the script to run. The results: practically instantaneous. “It took 0.016401052474976s to run this script”.

That can’t be right because my whole computer freezes for a good second whenever this script is called (I know its this script, its the only one running). I did notice that this script does run several times after its first run. Whenever it destroys a block, it recalls itself to calculate if it detects any other changes to the other blocks. Which is perfect, but it does it for every block in the model. I put a debouncer in, and it trims a good amount of the calls, but doesnt out right prevent it.

So, I wanna know if theres a way to found out WHAT is taking so much of my computer’s resources. If its something i should worry about, or if its just a studio thing. And if theres any way to prevent an event from being called several times all at once. (I already tried basic debouncer)

Thank you all for any advice!

There are a lot of resources in studio like the script performance tab and the microprofiler. Can you show the code that causes the issue?

I didnt wanna immediately show the code because trying to decipher someone else’s code is hell. Im going to look into this “script performance” rn. As for the script, here: Deadblockscript

The script performance tab shows a scripts activity and rate. You don’t really need to worry about the rate as long as it’s not insanely high (>10000). Anything above 3% activity will lag.

I will look into that and will let you know if that shows anything. Thanks

1 Like