There are a lot of good answers here, but I will reiterate on what @index_self said,
All of the solutions here will come with performance penalty. Moving data across parallel threads is costly, SharedTables
are slow, Bindables
and Actor:SendMessage()
as well. I don’t have numbers, but I can tell you it is slow to the point it is likely going to be slower than serial execution
If you call a bindable or Actor:SendMessage() every 20 second, that could work? Be wary of lag spikes though (if you do it on the client), as the frame on which the bindable was called will be longer. The more data, the laggier it is
Parallel programming is mainly useful for easilyish parallelizable tasks, but even more so on roblox (due to the poor implementation and/or lack of support within lua). I would highly suggest reconsidering the use of parallel lua. I’d say good use cases for parallel lua is compression/decompression (or serialization) of massive tables (if you can separate it in chunks), raycasting rending engines, stuff like that
Often times, lag comes from the roblox engine, for example, I have a ski lift system that doesn’t use the physics engine, and CFrames each chair every frame, and most of the lag comes from updating the CFrame of the chairlifts, more than calculations. I tried paralleling it (before roblox nerfed parallel lua), and the gains were eaten by the overhead, it wasn’t faster
There is also the option of making each parallel thread compute the data instead of requesting it from other threads. This involves having the state of the game be deterministic, ie, every thread ends up with the same result (in your case, PlayerData) given the player’s actions, so in a sense, you’d have multiple servers running the same tasks, which sounds counter productive, but could actually improve performance if the tasks aren’t heavy
Could you provide some examples of what you want to use parallel lua for?
Also, my suggestions for optimizing games will always be the Micro Profiler. Without it, you are just blindly optimizing things. The script performance tab is garbage (for reasons…)