Hi👋🏻
This is just a quick question:
What is Parallel in Roblox ?
Normally, scripts run procedurally, which just means that they run one function after another, which can be an issue if you’re trying to do multiple things at the same time. Parallel exists so that you can have multiple functions in the same script run at the same time. If you need help or have other question I’d be glad to help!
Thank you and best of luck!
You can eat dinner and then watch YouTube, or watch YouTube and then eat dinner, but not at the same time.
Parallelism lets you do both at the same time.
Can you make an example? I’m still confused ![]()
Look at what @Denneisk said, it’s a good analogy. With parallelism you can do more things at the same time, for instance running multiple loops at the same time. Without it, you need to run them one after another. Imagine a to-do list, normally you can only do one thing at a time but if you can utilize parallelism you can do everything at once.
Read Parallel Luau | Documentation - Roblox Creator Hub.
A modern example is machine learning, where parallel processing is utilized to train a model more efficiently. Here is an example in pytorch.
A more relatable example where parallel processing might be utilized is chunk generation in a game like Minecraft. Because the data of each chunk is independent, multiple processes can be ran in parallel to generate multiple chunks at once, speeding up generation time.
An example where parallel processing can be a bad idea when improperly implemented is writing to a file. Doing so can lead to race conditions and corrupted data as well as ambiguous file state. Thread-safe practices such as mutexes/semaphores/etc. should be used in this case.
Parallelism is tricky. There are some things you just can’t parallelize for the reasons stated above and more. Generally, if your code has to be executed sequentially to function, uses methods that are not thread-safe, is more costly to implement than is beneficial, or relies on the manipulation of shared memory, then parallelism is a poor choice. If your code doesn’t have these restrictions, then parallelism can be a huge performance gain.
Here’s a better analogy:
Let’s say you have 10,000 math equations to solve.
You are presented with 2 options, either:
Option 1
You solve each problem one at a time.Option 2
You gather 100 people that divide and gather, they each solve their own 100 math problems and everyone puts their solutions together into one final answer.Obviously, Option 2 is faster, this is the premise of parallelism, you take a task and break it into several smaller tasks that solve different parts of the problem that run at the same time.
This is why GPUs exist to run all of the complicated 3d math for graphics each at the same time for fast processing. CPUs can only do one at a time which is why they are much slower.
A lot of people (me included) do both at the same time
This kind of goes into Big O notation which makes me question if this is really a better option, best to not confuse him with wrong ideas about coding/logic.
Hey everyone!
I have a few questions about parallel:
Why should we use parallel?
When should we use parallel?
Parallel is “faster” because it allows you to use more resources
For example, running in serial (one core) means you use one core
If you run in parallel then you can use something like 8 cores on a CPU or thousands of weaker cores on a GPU (cant use GPU on roblox)
Using more cores also comes with some cost because you have to communicate between them and sometimes you have to clone the environment which uses more memory
Only use it for tasks that work with parallel
If you have to do something one after another, then it doesnt work
For something like terrain generation, every chunk can generate on its own in any order, which makes parallel very good
Something important to remember is that parallel can’t be used to expedite the speed of everything and if you try to do that you’ll just slow down the overall process. There’s been times where I needed to remove multi-threading from my scripts due to overall script performance decreasing.
