ive got a question, does making the server handle the loops save performance?
I believe letting the server handle loops may cause some server latency issues, but that would depend on how long the code is and how long the loop will be running for. If it’s not necessary to use a loop on the server, you can probably use it on the client to save some server performance.
However, remember that there are some situations where a loop wouldn’t even be necessary since there are other events for them (for example: Instance Property changes ‘Instance:GetPropertyChangedSignal("PropertyNameHere")
’; When a child has been added/removed from another instance ‘Instance.ChildAdded
,Instance.ChildRemoved
’; use TweenService instead of using (a for) loop(s) to animate a 2D/3D Instances; etc.).
Loops themselves are not highly suggested, since they may cause performance issues depending on how large the code is and how long the wait time is, so keep in mind that there can be other ways to achieve things without using loops.
I might be slightly wrong about this, but I’ll let others correct me.
Uhh you’re kind of asking two different questions
- Do loops hurt performance
- How should performance-hurting code be split between the server and the clients
No. 2 is not an easy question to answer. It depends on a lot of factors, and in the end you’re not getting out of testing the performance of your code on both the server and client. If your code is too slow in one context, offload it to the other. Although not all code can be freely moved from one to the other, but maybe you can compensate by moving some other code.
No. 1 is an easy question to answer, except it seems to be based in some confusion so… No, loops don’t hurt performance. Having a lot of computation work being done hurts performance, because only so much can be done every frame and if you exceed your budget then the game will have to slow down in one way or another to wait for said computation to finish. Loops are just a type of code that may hide work being done from inexperienced programmers. But there’s no difference between for i = 1, 3 do print(i) end
and print(1) print(2) print(3)
, so no it’s not the loops hurting performance. They just enable us to write repeating code in a way that has a lot less explicit repetition.
As gone over by the other people in this topic, this question is really dependent on what you are trying to do with the loop. In some cases, you need to run the loop on the server and in other cases, you can run it on the client. If you have a specific task you are trying to complete, we may be able to give you some suggestions if you tell us what you are trying to do.
my game is heavy on the client side , the client scripts has alot of loops so i just wondered if i can save more performance by letting the server do the calculations of a loop and then the client should only load the results of the loop not calculate it so the player can have better experience.
Having the server do intensive calculations would have the clients do less work.
Are you sure that your loops are intensive though? Just because something loops doesn’t mean it uses a lot of compute.
Are you sure your game is heavy on the client side? A lot of roblox games intentionally try to move tasks to clients to take load off the server, not the other way around.
If you gave more information it would be easier to say whether or not this would be a good idea. There are other factors like latency to consider too.
actually my game is a singleplayer game ,i dont think the server will struggle that much
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.