MadStudioRoblox / ProfileService

Universal session-locked savable table API
https://madstudioroblox.github.io/ProfileService/
Apache License 2.0
298 stars 158 forks source link

Replace wait() with SmartWait() #1

Closed ArchLand64 closed 4 years ago

ArchLand64 commented 4 years ago

I recommend replacing your wait() calls with something like SmartWait():

local Heartbeat = game:GetService("RunService").Heartbeat
local function SmartWait(timeToWait)
    timeToWait = timeToWait or 1/60
    local timeElapsed = 0

    while timeElapsed <= timeToWait do
        local timeWaited = Heartbeat:Wait()
        timeElapsed = timeElapsed + timeWaited
    end
    return timeElapsed
end

Clonetrooper demonstrates what can happen when using wait() on large scale projects here: https://www.youtube.com/watch?v=cj_21dL_W38

LM-loleris commented 4 years ago

Thank you for the suggestion!

From my current understanding, this sort of change would be of trivial effect to the stability and performance speed of ProfileService - wait() is only used in places where even a 50% offset in wait time would make no apparent difference.