Is there a way to do rust-like parallelism?

Hello! I’m coming from the Rust programming language, where a crate called rayon is used quite a lot. It provides parallel iterators (which is the main thing I would like) and no data races (even though that shouldn’t have really been an issue).

I was wondering if someone knew how to do something similar like rayon in roblox? Potentially, something like:

for i,v in parpairs(table) do

end

If possible, I didn’t want to use manual actors, as I personally think the way they currently work is a bit clanky, and this would be extremely convenient. Thanks!

2 Likes

Roblox released Parallel LUAU to their engine some time ago, it’s relatively new
You’ll need a BindableEvent
image

When the Event is called, connect a Method called ConnectParallel to it

Bindable.Event:ConnectParallel(function()
	local Array = {}
	for _,v in pairs(Array) do
		
	end
end)
Bindable:Fire()

You’re gonna have to do that with coroutines. I’m not aware of any packages that do this, but maybe those exist for Roblox.

EDIT: Coroutines are not parallel, but concurrent. Do not use those for iterating more efficiently through tables.

Roblox has Parallel LUAU it’s really interesting, and it’s relatively new, go check out the documentation

(PS, you can just use task.spawn() to create a second thread in the resource manager, not sure how much they differ from Coroutines though)

1 Like

You’re right. That is the way to go. Guess I’m getting old :slight_smile:

Then that makes me ancient, because ive been stuck using .p instead of .Position :123:

I’m not sure how exactly this is parallel. Does Roblox do automatic parallelization of iterators and events? Because what I was attempting to do was to get a Rayon like API in Roblox.