idk someone told me to use loops as less as possible. His argument was “You’re literally one task.wait() away from crashing the game”
I can provide an optimization tip regarding looping and rate
first open performance
Check your code
If your code rate is running faster than fps then it bad or slower than the intended fps rate(If it run on client)
I used to have a script that run at 120 rate per second but my fps was 60fps to fix this I use a scheduler basically makes a table containing all the functions and run through it.
Oh yes I know basics like this, I jsut wanna know more.
If your activity is high it might be memory leak go fix that or it at constant high activity then it bad code.
Another useless thing that you probably knew : Terry Davis said simplicity over complexity. So if you get a code you shorten it as much as possible.
From my experience studying off dev forum it’s just running code as least amount of times and rate as possible and reusing memory (Part cache).
Data structures and algorithms can help:
Cache in memory:
Would you say this tutorial from the docs is good?
What activity percentage and code rate should you try to stay below?
at best activity below 10 and rate always below fps. Making script using less random can improve on the activity and less retrying
Yep I would say Roblox’s documentation good didn’t exist previously but now is there showing it’s slowly improving.
There’s some interesting information on it like the built in rendering system. This justifies creating your own script to cull objects.
Culling - Culling describes the process of eliminating draw calls for objects that don’t factor into the final rendered frame. By default, the engine skips draw calls for objects outside the camera’s field of view (frustum culling), but doesn’t skip draw calls for objects occluded from view by other objects (occlusion culling). If your scene has a large number of draw calls, consider implementing your own additional culling at runtime dynamically for every frame, such as applying the following common strategies:
But cant fps vary between clients? I have a good PC so I average 60, but other players??
using one task.wait for a loop can cap the rate at the player’s fps
Um, well I usually just put a task.wait() right below
while CWeather do
-- Code
task.wait()
Also I don’t really use task.spawn/coroutines, never really have had to use it.
you don’t really need to bother about it I just use task.spawn because I was lazy moving the code down, coroutine and task.spawn main use are weirdly about programmer being lazy but it work great for scheduling an event or remove something or add something without halting
question, can coroutines cause memory leaks?
coroutine.wrap(function()
print("meow meow meow meow")
end)()
because you are creating a new connection no? or is it just calling a function
the garbage collector will clean up unused coroutines or there are no reference to that coroutine in the code once it done, if you happen to put a coroutine in a table(That will be use) it will definitely cause a memory leak as that table is being constantly used with a useless coroutine inside of it.
The only use i’ve heard of coroutines is to “spawn new threads” which um, don’t really see the use of. or making stuff happen at the same time, which again haven’t found much use.
task.spawn also, I’ve even worked on a horror game now and finished it but i’ve never had to use any of these library things. Not sure.
There’s this document from the creator of lua which shows you some optimization tricks .
(if you dont trust links then just google “lua optimization”)
Also try to always use events instead of loops.
Yes again I know basics like that, I just meant more. I’ll check out the link thanks.
I think my activity is fine and at best my scripts use 2% activity, but rate is something else.
The code rate can go up to 200-250/s, but the default roblox script (RBXCharacterScripts) also is around this code rate. So I’m not sure if my script is fine or not fine.