Brief Overview
What is parallel luau you may ask? Parallel luau is a way to spread the computation load into multiple cores with the help of Actors. This helps in reducing strain and lag from the heavy computations that you may use.
For more information, check out Parallel Luau
Possible Use Cases
- Bullet Raycast Computations
- Enemy AI Computations
- Terrain Computations
- Raytraced Renderer
- Parallelized Cryptography
Why use this over other options?
Parallelizer also offers minimal footprint because of its unobstructive and lightweight nature
You can check out the benchmarks here
Example Usage
Here is an example usage of calculting the nth root (2) from 1 to 4096, to be run in parallel
Note: Ensure the module is located where both the job scripts and the master script can access; for example, in ReplicatedStorage
local Parallelizer = require(path.to.module)
local Scheduler = Parallelizer.CreateJobScheduler(script.Job, 256, script) -- 256 workers/actors, actors stored below the script
local RootInstruction = Parallelizer.CreateInstructionData({2}) -- {2} is the data to send to the actors, preferably for constants
-- Calculate the root of 1 to 4096 with each actor equally doing the same number of root operations
Scheduler:DispatchEquallyAsync('CalculateRoot', 4096, function(result)
print(result) -- The result in an array
Scheduler:Destroy() -- Destroy when no longer used further (only for memory cleanup purposes)
end, RootInstruction)
-- The Dispatch function is asynchronous, meaning it won't yield - so the succeeding code will run unobstructed
Actor/Job Script (located under the main script):
local Actor = script:GetActor()
-- Ensure we don't run as a non-actorized script?
if not Actor then
return
end
local Parallelizer = require(path.to.module)
-- id is the index of the thread, which is in the range [1, threadCount]
Parallelizer.CreateThread(Actor, 'CalculateRoot', function(id, instruction)
return id ^ (1/instruction[1])
end)
Important: The create thread callback function expects a return value.
Examples
Benchmarks & Comparisons
Benchmark settings:
- 256 actors
- 8192 threads
- 32 task assigned per actor
- 100 iterations
- Non-native environment
Hardware (the only stuff I have ):
- Intel(R) Core™ i7-4770K CPU @ 3.50GHz
Benchmark Source
Parallelizer:
benchmark_parallelizer.rbxm (3.4 KB)
ComputeLua:
benchmark_computelua.rbxm (31.0 KB)
Parallel Scheduler:
benchmark_parallel_sched.rbxm (6.8 KB)
Task | Parallelizer | ComputeLua | Parallel Scheduler |
---|---|---|---|
nth root (n = 2) | 22ms | 40ms | 25ms |
Credits & Footnotes
Warning: Messing with generally all parallel code is prone to crashes, save a backup or publish the place to avoid your progress being loss.
Could anyone suggest a stress test method I could use? I’m trying to test the capabilities of this module before I’m going to redo my shader.
If you have any suggestions in mind, feel free to share them here! Or if you’ve encountered issues with the module, don’t hesitate to ask for help! I will assist you through the process as soon as possible.
Thanks to ComputeLua once again for inspiring me and giving hope to make the shader - and this. Most of the API is similar to ComputeLua’s (and also a bit of unity’s)
This module is under the MIT license
Version History
0.1.6: Parallelizer.lua (4.1 KB)
0.1.5b: Parallelizer.lua (3.9 KB)
0.1.5a: Parallelizer.lua (3.4 KB)
0.1.5: Parallelizer.lua (2.7 KB)
0.1.4: Parallelizer.lua (2.4 KB)
0.1.3: Parallelizer.lua (2.4 KB)
0.1.2: Parallelizer.lua (2.2 KB)
0.1.1: Parallelizer.lua (2.1 KB)
0.1.0: Parallelizer.lua (2.4 KB)
Release: Parallelizer.lua (2.2 KB)
- What the sigma
- Ok cool
- Couldn’t think of a use for Parallel Luau
0 voters
- Yes
- no why
0 voters