IN BETA PHASE
This library is relatively new, lacking features, and the API is subject to change, though it has been unit tested and seems to be stable enough for my ASCII Shader
Brief Overview
Weave is a job-oriented parallelism library for Roblox built on Actors and callback-based dispatch.It is the successor to Parallelizer, which used a buffer-based execution model. After some profiling and experimentation, that approach proved to introduce unnecessary overhead and often reduced performance rather than improving it.
Weave uses a job-based model that batches synchronous work across worker Actors and rejoins results through callbacks, which has more predictable performance and lower scheduling overhead.
Notable Optimization Tricks
- Uses BindableEvents instead of SharedTables for parallel-serial communication
- Because parallel to serial communication is expensive; even with bindable events (the best SharedTable alternative I could find), instead of firing after each batch, each actor only fires the remote ONCE for any number of threads to reduce traffic
- This library is callback-oriented instead of promise-oriented due to the bulky nature of promise libraries. It’s simpler and way faster
- It’s recommended to set the workspace’s SignalBehavior to Immediate for the maximum performance (because we’re using remote events which behavior depends on the signal behavior)
What is this even used for?
- Terrain Generation
- Intensive Raycasting
- Custom Renderers
- Bullet Projectile Physics
- … and other computationally heavy systems
Usage
-- master_script.server.luau
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local weave = require(ReplicatedStorage.weave)
local dispatcher = weave.dispatcher.new(8, script.Parent.worker)
local origin = Vector3.zero
local dir = Vector3.yAxis -- up
local threadCount = 200*200
dispatcher:DispatchDeferred("ray", threadCount, function(buf)
print(buf)
end, nil, origin, dir)
--!native
--!optimize 2
-- worker.server.luau
local actor = script:GetActor()
if not actor then return end
local weave = require(game.ReplicatedStorage.weave)
local kernel = weave.kernel.new(actor)
kernel:On("ray", function(id, origin: Vector3, dir: Vector3)
local res = workspace:Raycast(origin, normal_dir.Unit * -1000)
return res
end)
kernel:Ready()
It’s recommended to put weave somewhere easily accessible and independent, like in ReplicatedStorage
Installation
> Pesde
pesde add artzified/weave
> Github Release (rbxmx)
Examples
Terrain Generation:
terrain.rbxl (80.2 KB)
NOTE: I WILL NOT ENGAGE IN A CYCLIC CONVERSATION WITH YARIK.