How much does using RunService.RenderStepped affect optimization?

i’ve recently found out about RunService.RenderStepped and ever since i’ve been using event-based code way less, since running it made it way easier to me than connecting a bunch of events in many cases, but the more i use it i think that it probably affects optimization and frame rate quite a bit. how does using it exactly affect optimization and frame rate, is it fine to use it?

Can you give an example of how you’re replacing event-based code with renderstepped?

i don’t have that many examples, but in most of the cases i use RenderStepped for straight projectiles using the delta argument it has; other than that i also use it to check if multiple statements are right and do something if they are, or stop doing it if they aren’t.
a common simplified code example from something i’m currently working on is like this.

local hasItem = true
local trayEquipped = true
local isFull = false
RunService.RenderStepped:Connect(function()
    if hasItem and trayEquipped and not isFull then
        createPrompt()
    else
        deletePrompt()
    end
end)

I’m pretty sure heartbeat is better for that. Use renderstepped if ur doing something with the character or the camera, if not just use heartbeat.

1 Like

You want Heartbeat wherever it’s possible to use it. I stole this image from this thread that explains it really well. Basically, Heartbeat doesn’t slow down the execution of other parts of the frame render like RenderStepped does. Rendering can happen while HeartBeat code is running, but RenderStepped has to finish before Roblox will even start rendering the frame.

image

4 Likes

That pattern is not terrible, and RenderStep is fine for GUI stuff (as long as you’re not doing anything too intense).

It’s fine for performance, unless you start seeing an issue :slight_smile:

However, it may have downsides in terms of integrating into roblox. I discussed that here: Question about having a loop or base it of a returned value - #2 by nicemike40

2 Likes