Help with using multi-threading

I have a simple program taking in lines of instructions, with performing math, reading/writing from indexes in an array, with there being functions to queue for pixels to be painted, which once the queue is flushed, it would be drawn into a pixel display, this is the only outside-script output the program does.

How can I use multi-threading to better optimise this?

1 Like

I’m not sure what you are trying to accomplish with parallel computing, do you have a video/photo/example of the pixel painter? What is the pixel painter used for? How is it being used? Is the current method slow? What other problems does it have right now with serial computing?

im developing a program to run a custom programming line-language, similar to Mindustry’s logic system, each line is commit one after the other (unless it’s a jump function), 8 lines run per frame and the pixel display refresh every 2 frames

You probably won’t benefit from parallel computing. It would be a lot of work to set up for very for almost no noticeable change.

You should be able to execute those 8 lines before that frame ends. Same goes with pixel display refreshing. If you’re worried that your code won’t be complete before the frame ends, I’d say it’s super unlikely. Assuming you’re running your frames 60 times per second (60 FPS), I would guess that it should be possible to execute around 10,000 lines per frame as opposed to your requirement of 8.

I recommend you continue with the method you have before. Either a for loop and execute the instructions going down or however you do it.

There are only certain types of applications where parallel computing would shine in, otherwise I would say it’s unnecessary work. But if you really want to do it, you can check out Parallel Luau | Documentation - Roblox Creator Hub. They have example code on how it’s used.

10,000 lines per frame means 20,000 functions per frame (per player), each line uses 2 functions, 1 to load any variables using @var_name to have its value loaded into the function, then the 2nd function to actually run the proccess

Also an example of some of the 2nd functions:


v is a table of variables into the function, cache is a table unique per player

Your original goal is to run 8 functions per frame right? You won’t have to worry about doing 20,000 lines per frame.

alright, although now you state that I’d probably change to 25 lines (50 functions) per frame

Just keep in mind that it’s an estimate. I have no idea how you’re setting it up so the true value may be lower or higher. If you find that there are glitches when running the code, try dialing back the rate.