So, I remember a few years back there was a huge fuss going on that using getfenv, setfenv, _G and shared will disable luaU optimizations. Is that still the case nowadays? I’m getting really tired of writing long paths over and over again just to require a module, so I’m gonna make an import equivalent.
Yeah I’m pretty sure they still disable luau optimizations.
that’s so sad… roblox either forces us to use its flawed module system over and over or put everything into a few scripts with little to none proper ide tools which often results in hilariously hard-to-work-with big chungus of a script
when your system gets to thousands of lines across multiple modules or in the same script it gets hard to mentally keep track of what’s happening, and you’re basically forced to do it with roblox studio’s lack of tools
Documentation is important. You will feel the same problems with
getfenv since there is no clear way to tell what script is doing what or where something is defined
I dont care about luaU optimizations and i still use getfenv, setfenv, _G, shared and i couldnt care less
in short terms use it anyway until you cant use it anymore
What exactly are the Luau optimizations anyway? I was hearing about this when I was talking to a friend about using :sub() vs string.sub() (since :sub() disables optimizations apparently)
so like example
instead of using
while task.wait() do
you use this
why? because while task.wait() do end can start lagging if there is way too many while task.wait() do end loops
nothing bad will happen if you use while task.wait() do end loop only once
as soon as you dont make more and more while task.wait() loops i think you should be fine
An equivalent example would be
while game:GetService("RunService").RenderStepped:Wait() do
Also a while loop doesn’t remove optimizations, these two things are the same except the connection runs in it’s own thread.
Never heard of this before. Can you back up these claims? They should perform almost exactly the same because task.wait() fires every frame (like .RenderStepped).
I don’t think _G or shared disable any Luau optimizations, but they are still regarded as bad practice for many reasons (organization, losing types, race conditions…)
However, get and setfenv do disable optimizations, and the use of these functions will be deprecated:
while task.wait() do
if you run this on client its gonna slowly start lagging then its gonna be unplayable (reason: too many while task.wait loops)
Well obviously, you’re creating a new thread every time RenderStepped runs.
That also happens when you do this:
I don’t get your point. If you have any proof that .RenderStepped performs better than task.wait(), please show me. If not, please don’t spread misinformation.
Edit: Even a Roblox staff member said you were wrong.
Any calls to
task.wait will be resumed at the same time as the
Heartbeat event so event choice aside there should not be a noticeable difference in performance unless you introduce a memory leak in one but not the other.
Im not inclined to believe doing those will disable any optimization. Have you found any tests that suggest this is the case? It seems to me that luau optimizes very little anyway. In particular it does not take advantage of types being annotated or known at compile time.
how am i wrong? the code i sent you also causes crash
edit: uhh i think your both are wrong
i tried your .RenderStepped crash in studio and it didnt crash at all! (while task.wait() do end with renderstepped crash works tho and it starts lagging a little bit)
Show your code. I highly doubt a Roblox engineer is wrong. My point is .RenderStepped and task.wait() perform the exact same. Your point is that .RenderStepped somehow performs better than task.wait(). Understood?
i copy pasted your code
put it as localscript into ReplicatedFirst and it didnt crash
copy pasted this:
while task.wait() do
put it into the same localscript and it started lagging a little bit
In their code they’re using a RenderStepped connection in a RenderStepped connection while in your code you’re using, what is equivalent of a Heartbeat connection, in a RenderStepped connection. A RenderStepped connection resumes quicker therefore it is laggier and is not because there is a difference with a whole loop and a connection.
I’m sure their point was that using a while loop is less performant than using a connection and I don’t think they understand the difference between RenderStepped and Heartbeat.