Another day I was sitting in studio and working on optimization when of my friends asked if I could share my module with him I thought that I should share it to public. Basically made for simple non-visual related stuff that you don’t really need to run every frame which helps CPU time.
Source
GitHub:
Marketplace asset:
Usage Example
local FramerateManager = require(script.FramerateManager)
-- Test function
local function TestJob(deltaTime)
print("Job running at",1/deltaTime,"frames per second.")
end
local job = FramerateManager.CreateHBJob(TestJob,{FrameRate = 1}) -- create a job with given frame rate (frames per second)
Is this module not just something along the lines of this function
local function bindToHeartbeat(interval: number, fn (dt: number) -> ()): RBXScriptConnection
local last = os.clock()
return RunService.Heartbeat:Connect(function()
local t = os.clock()
local dt = t - last
if dt < interval then return end
last = t
fn(dt)
end)
end
bindToHeartbeat(1, function(dt)
print(dt) -- around 1
end)
Pretty much it but it doesn’t create so much connections, which saves a little of memory that in big quantity can save a lot of it, and also support pausing function if you need so.