Hey! Just wanted to share a resource i’ve recently made to improve my experience with parallel lua.
Context
Now, the problem with parallel is you cannot call task.desync or task.sync a ton of times as these functions are quite expensive.
This lead me onto some creative thinking and I eventually wondered onto the idea of a Scheduler.
Example
Lets say, for example we had a simple loop which set the CFrame of a part, this is how you would do that using the scheduler.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ParallelScheduler = require(ReplicatedStorage.ParallelScheduler)
local Object = script.Parent
task.desynchronize()
while true do
task.wait(1)
local RandomCFrame = Vector3.new(math.random(), Object.Position.Y, math.random())
-- Create a new job!
ParallelScheduler.Job(
-- What we want to do
"Set", -- we want to set a property
-- Object, Property, Value
Object, "CFrame", Object.CFrame + ((math.random() > 0.5 and -RandomCFrame) or RandomCFrame) -- What we're setting
)
end
The above stops us from calling task.sync/desync a bunch of times as that may have an impact on performance.
Api Document
Source Code
In addition to this, potentially we could add in more functionality to validate if a thread is running in serial or not. As of right now though this should give us basic control over executing serial jobs in parallel
Another great resource for parallel lua is this Worker Threads module