NSSTC / sim-ecs

Batteries included TypeScript ECS
https://nsstc.github.io/sim-ecs/
Mozilla Public License 2.0
84 stars 12 forks source link

improve execution-pipeline-caching #26

Closed minecrawler closed 2 years ago

minecrawler commented 3 years ago

While there is caching for execution-pipelines (the order in which systems run, one pipeline per state), it is not used optimally. The cache is tested on every state push, but run(), for example, starts a new build without checking the cache. Also, there is no way to prepare the cache for certain states (or all of them) at a user-defined point, which means that a state-push may mean hidden, unexpected costs. I imagine a public method, which takes a state and then prepares and caches a pipeline.

minecrawler commented 3 years ago

Note: There already is a method to prepare the pipeline (world.prepareRun()). It will, however, change some internal fields, so it is not useful to prepare another state than the one running.

It should be possible to use this method to prepare a state and pass the result of the method to world.run() and world.dispatch(). This also needs more attention in regards to a system's life-cycle.

minecrawler commented 2 years ago

The new scheduler already caches stuff a lot. Even when changing to a different schedule, only previously unused systems will be initialized and then cached. This could be improved by offering an API to initialize a schedule at a user-defined time instead of when changing states. All in all, I get the feeling that changing states is a lot faster now and does not require calculations and pipeline-building anymore, so I'll close this in favor of more concrete improvements.