MULTI-THREADING on ROBLOX?!
HTML-код
- Опубликовано: 11 сен 2024
- This video takes a look at Parallel Luau and how we can use Actors to separate our scripts into multiple threads. This spreads the workload of executing code more evenly, improving the frame time of your game!
Parallel Luau should mainly be used for any kind of heavy calculations that will eat up your frame time, otherwise, it's not likely your game will benefit unless you're already experiencing poor performance in your projects.
Ever wanted to learn Roblox Studio & scripting? Check out my course:
bit.ly/LuaScri...
Use code RBLX_DEV for 33% off!
My linktree:
linktr.ee/crus...
Happy scripting!
Something I recommend is not multi-threading everything. I spoke to someone and they said don’t multi-thread it can make lower-end devices crash quite often.
thats cause older cpus lack propper mutithreading capability. so it cam cause crashes.
@@BockyDuh yeah, lower-end devices as i said. CPU's are interesting though. they execute code differently.
@@ipadgeek05 yeah. Mostly
its older arcatechture cpus.
WE DON'T GIVE A DAMN ABOUT PEASANTS ❌🚫⛔
No just dont muiltithread in general. Roblox is serialized for stability. If a chunk of data is access twice over from multiple threads of scripts and one decided to modify it. It causes data racing which can take out all the scripts running on the effective data chunk. Its MUCH safer to run on roblox's serial execution. This WILL happen on any device.
This taught me more about debugging which is really good to know if you're an advance scripter
will definitely be using this for my mesh deformation ocean so thanks! I've been trying to optimize it as much as I could for months and knew I should've been using this but it seemed so daunting. It'll be a pain to implement considering all the large module scripts associated with my system but now i have some motivation at least lol
good luck!!!
i have done it, its possible gl
goodluck man
omfg your explanation is so good, i understood everything from this, thank you
This is really perfect for my project. I'm making an RPG with Dark Souls inspired enemy AI who make many different decisions based on many different math calculations. I was worried having possibly hundreds of complex AI might cause performance issues like Deepwoken has, however with this I'll be able to optimise my game efficiently. Really nice video, I have instantly liked and subscribed.
goodluck with your project!
Thanks a lot! I'm now going to run millions of square root calculations on the local player when they're fighting in PVP to make them break their computer when they lose.
Seriously though. This was useful.
next it's gonna be cuquantum in luau
This is an absolutely great video you explained it so well i bet even a new scripter could understand it
Thank you man, I made collision detection with spherecasting and the somehow my game was lagging. This definitely helps with what I was going for
Thank you i was really curious about this and i think it's a very interesting concept within lua their is actually alot more then i thought to it
Excellent video, thank you! I've only seen 2 of your videos and I bought your Udemy course, I'm sure it's worth it.
Thanks for your support!
This is going to help so much, thank you.
You should make a video on editable meshes and images
No way this bro made a deer tornado while tryna explain parallel executing and task desynchronization
Thank you for this tutorial im can optimize my game! 👍
Making a Helldivers type game for fun.
I was thinking of using this to manage the NPC's but so far the tasks getting desynched is too much a pain to deal with lmfao.
Very helpful and perfect tysm!
And I still get ~20fps average while before I had 60. damn you developers!!
Quick question! At 11:25 you made 3 connections and created a profile for each process, in order it has the numbers "1", "2" and "3". But in the profiler it says "3", "2", "1". So it's in order.. but reversed. I don't quite understand why though?
Good eye! While I'm not exactly sure the reasoning behind why this happens, this same pattern exists with regular connections as well. It must be some kind of internal thing relating to task scheduling.
😌 Amazing video. Why not Roblox Engine set their defaults from Serial to Parallel so there is no need to make some extras for parallel computing. Like just calling some function then wallah, the scripts are now set to parallel or Roblox Engine can automatically assign task computations for each available worker of the CPU 🤔then Player and Game Dev will surprise that the game is now optimize by 1million times
It will crash low end devices if things are parallel by default.
What font did you use in the video? I want to use it for studio.
JetBrains Mono!
@@crusherfire1 How do i get that in studio?
If I had a class with some method like;
local Entity = {}
--more class stuff
Entity:Pathfind()
How Would I use multithreading, since even if I have 100 entities, they all use the same pathfind function???
If anybody could help me with this, it would be greatly appreciated!
AWESOME dude
NICE VIDEO MAN!!!!!!!!!!!!!!!!!!!!!!!!!!
(what i said is wrong read replies if anyone else comes by this)
one thing you shouldve mentioned is task.spawn, this does one thing similar to actors and runs the code in parallel, so you don't need to make a script in a separate actor for everything, you can just use task.spawn to run multiple npcs in paralell for example.
thanks so much for this video though, this will help a lot, a question though, are there limits to what can be given a profile label? for example i tried to label a while loop inside of a function but i've yet to see it anywhere despite it triggerring most of the functions of my NPCs
I'm sorry, but that is incorrect. The task library, like task.defer() and task.spawn() execute functions in a new coroutine thread, not a processor thread. I mentioned that coroutine threads are not the same as processor threads.
Coroutines still execute in serial, except, they can have their flow manipulated using yield functions like coroutine.yield(). Only 1 coroutine executes at a time. So, no, task.spawn() does not run code in parallel.
@@crusherfire1 dang i misread the profiler then, so is it possibile to run multiple loops within the same code in paralell or is that done with task.desynchronize?
@@decat4 In order for code to be executed in a separate thread, the script where the code is executing has to be within an actor.
If you have two while loops in the same script and both running in parallel, they will still be executing one after the other because they are inside of the same script in the same actor (executing on the same thread). However, those two while loops will also be separate from the current thread executing in a different thread.
If those while loops are split into two separate scripts under two separate actors, then the two while loops will be executing in separate threads at the same time.
Making a script a child of an actor doesn't make the code automatically run in parallel. You must define where using task.desynchronize() to run in parallel and using task.synchronize() to run in serial.
Or you can also use :ConnectParallel() on events which automatically runs the connected callback in parallel without needing to call task.desynchronize()
@@crusherfire1 huge thank you for the explanation,
"Luau" ok. Lets not talk about who thought of this name
the graph doesnt show up for me
thank you
Hello, I am taking the course called Roblox studio on the Udemy platform. However, the course currently does not have a Turkish subtitle option. I have a request to add Turkish subtitles. Help me in this matter.
Udemy only offers a couple automatic subtitles, so I have to manually translate and add subtitles to Turkish which may take me a bit of time.
I'll try to add them ASAP
@@crusherfire1 Thank you very much! I wish you good work!
This is a great tutorial, I just have one question. It seems that parallel luau can only parallelize scripts, not any function in that script. This is a problem as I have a script that (hilariously) does need to iterate over a table 1 million times. Due to my array being separated into chunks, I would love to use parallel lua to run all the chunks in parallel, hopefully increasing performance. But it seems this is not possible as this only takes place inside one script. Also what happens if you try to run in parallel more scripts than there are workers?
Yes, you would have to figure out a way to separate your code into multiple scripts, as you need multiple actors to split into separate threads.
In the case you have more actors than threads, the workload is distributed across all threads (like the deer in the video). Roblox recommends splitting long computations into separate scripts, as the granularity allows for more even distribution of tasks among threads.
@@crusherfire1 Is it possible to process in parallel using remote functions? Using remote functions would simplify spreading the data around and ease collection of it, though invoking a new actor might be a struggle.
@@osanixian1499
The properties for remote functions and bindable functions aren't labeled with a safety label, so I'm gonna say no?
Of course, you can easily just set up a test and see if you're able to use to it in parallel. If it errors, then you've got your answer.
I'm not sure why you would need to use a remote function/bindable function? If you need to share data between actors, use a bindable event, you can use the Actor messaging system, and there is even a data type called SharedTable that was made specifically for use in Parallel Luau, and you can store them in a shared registry.
create.roblox.com/docs/reference/engine/datatypes/SharedTable
What about Serial killers and Parallel killers?
uhhh
serial killers kill one by one and parallel killers kill many at once or something
parallel killers are scarier man, remember to pray
guy went from being russian to a coder 💀
youre so cool
youre so cool
Parrarel me amu???
multi
ViewportFrame tutorial or else...
or else what 🤔
set viewportframe's current camera property to a camera (any camera)
it will now render parts and models *parented to the viewportframe*, if ViewportFrame.CurrentCamera can see it.
it won't look high quality but there's no good way to fix that so lol
buddy im pretty sure most people know that but its the camera positioning that gets most people@@thisisaperson1536
a
So, how do i achive something like task.spawn that uses actual different threads
make a different thread
do u have a discord?
I do, but it's not public
@@crusherfire1Are you talking about discord server or personal account
@@idoscripts I have a server, but it's private (reserved for my students).
@@crusherfire1 How do I become a student?
Never mind, figured it out. Is there any chance I could get a fan discount?
I did
```for i = 1, math.huge do
--blah blah the coede math.sqeurit
end```
it's vame crs game crashed
nvm it loaded