Does anyone know the cost of Loop's on the player's FPS?

Does anyone know the cost of Loop’s on the player’s FPS? Because I’m making a game that I want everyone, soon to be mobile and console, to play my game. I also want to completely minimize the number of recourses being used on the client’s device.

By Loops, I’m reffering to For i, I pairs / In Pairs, RunService.Heartbeat(), tick() os(), etc…

It depends on what you’re doing in the loop

1 Like

I know that every loop will vary in the cost of recourse’s being used though. I saw a chat on the forum once that was describing the differences of the loop-able functions, and how they differ in the consumption of the client’s recourses.

Each loop can have a print() function in it, but all of the loops will differ in the amount of recourse’s used and also will go at different speeds.

Not sure what you’re trying to ask though. The content of the loop is a lot more important wrt run time than the type of loop?

1 Like

I’m trying to ask, what loops increase lag the most and the least?

The difference is so small it shouldn’t even be a thought. If you want to increase speed you should look into better algorithms

1 Like

Most of your examples aren’t loops so I’m not sure about that—if you need Heartbeat or Stepped for something, you have to use it.

There is no good general answer to your question.*

First, use the tool you need to use. There’s no choice there.

Then, see if you even have a performance problem in the first place. No performance problem? No need to worry about optimizing.

Finally, only once you’ve confirmed you have a performance problem on real devices, realize that your performance problem is not due to the exact type of loop you used and look elsewhere.

*Technically for `for` loops…

In general prefer for .. in ipairs(t) , for .. in pairs(t) and for .. in next, t over for i=1,#t. Roblox optimizes those to avoid function calls.

1 Like