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!

Комментарии • 83

  • @ipadgeek05
    @ipadgeek05 7 месяцев назад +34

    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.

    • @BockyDuh
      @BockyDuh 7 месяцев назад +5

      thats cause older cpus lack propper mutithreading capability. so it cam cause crashes.

    • @ipadgeek05
      @ipadgeek05 7 месяцев назад +5

      @@BockyDuh yeah, lower-end devices as i said. CPU's are interesting though. they execute code differently.

    • @BockyDuh
      @BockyDuh 7 месяцев назад +1

      @@ipadgeek05 yeah. Mostly
      its older arcatechture cpus.

    • @alexanderdouble
      @alexanderdouble 3 месяца назад +9

      WE DON'T GIVE A DAMN ABOUT PEASANTS ❌🚫⛔

    • @Te.le.
      @Te.le. 2 месяца назад +1

      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.

  • @Dumdidiot
    @Dumdidiot 6 месяцев назад +11

    This taught me more about debugging which is really good to know if you're an advance scripter

  • @synkka1221
    @synkka1221 7 месяцев назад +23

    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

    • @steechy
      @steechy 7 месяцев назад

      good luck!!!

    • @lalaly2011
      @lalaly2011 7 месяцев назад

      i have done it, its possible gl

    • @justsomeguy8597
      @justsomeguy8597 7 месяцев назад

      goodluck man

  • @Krysiuba1
    @Krysiuba1 7 месяцев назад +7

    omfg your explanation is so good, i understood everything from this, thank you

  • @Illumina1414
    @Illumina1414 7 месяцев назад +7

    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.

  • @uncommonsaucers2355
    @uncommonsaucers2355 7 месяцев назад +2

    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.

  • @acelaox6836
    @acelaox6836 7 месяцев назад +17

    next it's gonna be cuquantum in luau

  • @ItsSpaceManPlays
    @ItsSpaceManPlays 3 месяца назад +1

    This is an absolutely great video you explained it so well i bet even a new scripter could understand it

  • @JoshTheKneeSnatcher
    @JoshTheKneeSnatcher 6 месяцев назад +1

    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

  • @Czectly
    @Czectly 7 месяцев назад +2

    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

  • @fabiandidiercobobitriago
    @fabiandidiercobobitriago 6 месяцев назад +1

    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.

    • @crusherfire1
      @crusherfire1  6 месяцев назад +1

      Thanks for your support!

  • @MiniSodaDev
    @MiniSodaDev 7 месяцев назад +1

    This is going to help so much, thank you.

  • @nin9578
    @nin9578 7 месяцев назад +1

    You should make a video on editable meshes and images

  • @SlightlySchizophrenic
    @SlightlySchizophrenic 6 месяцев назад

    No way this bro made a deer tornado while tryna explain parallel executing and task desynchronization

  • @user-qk5yh6vs5k
    @user-qk5yh6vs5k 7 месяцев назад +1

    Thank you for this tutorial im can optimize my game! 👍

  • @honkhonk8009
    @honkhonk8009 4 месяца назад

    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.

  • @mewristem
    @mewristem 7 месяцев назад +1

    Very helpful and perfect tysm!

  • @Nykomil
    @Nykomil 7 месяцев назад

    And I still get ~20fps average while before I had 60. damn you developers!!

  • @MarkoBrainz
    @MarkoBrainz 4 месяца назад

    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?

    • @crusherfire1
      @crusherfire1  4 месяца назад +1

      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.

  • @macjoeplays
    @macjoeplays 6 месяцев назад

    😌 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

    • @lordnazzer
      @lordnazzer 4 месяца назад

      It will crash low end devices if things are parallel by default.

  • @Sanchayan_Mallick
    @Sanchayan_Mallick 4 месяца назад +1

    What font did you use in the video? I want to use it for studio.

  • @YellowPeace
    @YellowPeace 20 дней назад

    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!

  • @edgyman519
    @edgyman519 3 месяца назад

    AWESOME dude

  • @cracktusdev
    @cracktusdev 7 месяцев назад

    NICE VIDEO MAN!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @decat4
    @decat4 7 месяцев назад +1

    (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

    • @crusherfire1
      @crusherfire1  7 месяцев назад +2

      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.

    • @decat4
      @decat4 7 месяцев назад

      @@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?

    • @crusherfire1
      @crusherfire1  7 месяцев назад +1

      @@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()

    • @decat4
      @decat4 7 месяцев назад

      @@crusherfire1 huge thank you for the explanation,

  • @stavros222
    @stavros222 7 месяцев назад

    "Luau" ok. Lets not talk about who thought of this name

  • @kokobroxd
    @kokobroxd 4 месяца назад

    the graph doesnt show up for me

  • @justsomeguy8597
    @justsomeguy8597 7 месяцев назад

    thank you

  • @SudoSed
    @SudoSed 7 месяцев назад

    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.

    • @crusherfire1
      @crusherfire1  7 месяцев назад +1

      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

    • @SudoSed
      @SudoSed 7 месяцев назад

      @@crusherfire1 Thank you very much! I wish you good work!

  • @osanixian1499
    @osanixian1499 7 месяцев назад

    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?

    • @crusherfire1
      @crusherfire1  7 месяцев назад

      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.

    • @osanixian1499
      @osanixian1499 7 месяцев назад

      ​@@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.

    • @crusherfire1
      @crusherfire1  7 месяцев назад

      @@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

  • @Kitsune_Dev
    @Kitsune_Dev 7 месяцев назад

    What about Serial killers and Parallel killers?

    • @thisisaperson1536
      @thisisaperson1536 6 месяцев назад +1

      uhhh
      serial killers kill one by one and parallel killers kill many at once or something
      parallel killers are scarier man, remember to pray

  • @chan3_.
    @chan3_. 7 месяцев назад

    guy went from being russian to a coder 💀

  • @j_ray01
    @j_ray01 5 месяцев назад

    youre so cool

  • @ExoticFoxy
    @ExoticFoxy 7 месяцев назад

    Parrarel me amu???

  • @elainecristina6215
    @elainecristina6215 7 месяцев назад

    multi

  • @friendlybuilder2414
    @friendlybuilder2414 7 месяцев назад +1

    ViewportFrame tutorial or else...

    • @crusherfire1
      @crusherfire1  7 месяцев назад

      or else what 🤔

    • @thisisaperson1536
      @thisisaperson1536 6 месяцев назад

      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

    • @friendlybuilder2414
      @friendlybuilder2414 6 месяцев назад

      buddy im pretty sure most people know that but its the camera positioning that gets most people@@thisisaperson1536

  • @letter-a
    @letter-a 7 месяцев назад

    a

  • @SPDM_Riky47
    @SPDM_Riky47 6 месяцев назад

    So, how do i achive something like task.spawn that uses actual different threads

  • @idoscripts
    @idoscripts 7 месяцев назад

    do u have a discord?

    • @crusherfire1
      @crusherfire1  7 месяцев назад +1

      I do, but it's not public

    • @idoscripts
      @idoscripts 7 месяцев назад

      @@crusherfire1Are you talking about discord server or personal account

    • @crusherfire1
      @crusherfire1  7 месяцев назад +1

      ​@@idoscripts I have a server, but it's private (reserved for my students).

    • @idoscripts
      @idoscripts 7 месяцев назад

      @@crusherfire1 How do I become a student?

    • @idoscripts
      @idoscripts 7 месяцев назад

      Never mind, figured it out. Is there any chance I could get a fan discount?

  • @tal5667
    @tal5667 5 месяцев назад

    I did
    ```for i = 1, math.huge do
    --blah blah the coede math.sqeurit
    end```
    it's vame crs game crashed

    • @tal5667
      @tal5667 5 месяцев назад

      nvm it loaded