matter-ecs / matter

A modern ECS library for Roblox
https://matter-ecs.github.io/matter/
MIT License
70 stars 13 forks source link

Support Actor/Threads #43

Open iamthekk opened 9 months ago

iamthekk commented 9 months ago

As projects grow in complexity and size, the ability to perform operations concurrently becomes increasingly critical. Implementing multithreading support could offer substantial benefits.

Ukendio commented 9 months ago

Maybe in the future when we have pipelines this is more plausible. The main problem is knowing what data is being written to and when. And for that we need systems to be aware of each other - which they aren't right now.

i kind of feel like you would need a prepared query that declares what components are being used or else I am not really sure how we would even begin to partition which components to a specific actor VM.

However with pipelines we can implement sync points between systems and also possibly discern what- and where data is changed. And for this we want a declarative API that helps coordinate this.

But beyond the technical hurdles, actor synchronization itself is really expensive that I am not sure if inter-system parallelism is worth it. AFAIK no benchmarks out there has actually shown that parallelizing ECS in Luau has any performance benefits. There are however examples of the opposite.

LastTalon commented 9 months ago

But beyond the technical hurdles, actor synchronization itself is really expensive that I am not sure if inter-system parallelism is worth it. AFAIK no benchmarks out there has actually shown that parallelizing ECS in Luau has any performance benefits. There are however examples of the opposite.

This is the key issue in my opinion. The cost of synchronization through actors (which we currently would have to do) outweighs the benefits of parallelization in any benchmarks, tests, or prototypes I've seen.

We can easily support concurrency through pipelines if there's a valid use-case for that, but at the moment I can only conceive of a negative (losing system order determinism). If you have a use-case for system concurrency that doesn't rely on parallelism (single-threaded concurrency) for which this downside might be worth dealing with, let us know.

LastTalon commented 9 months ago

Marking this as externally blocked on the Roblox actor model for now.