Amethyst Site

Discourse Hub Dev

This is a experimental feature, ignore this.


Launch Hub

Legion: Component change tracking

First of all thanks for the legion’s beautiful code.

I am trying to implement a reactive asynchronous scheduler to run in a server side application. The problem is that in my task there are no frames per se, but a constant stream of events. So my idea is to run each system when system-readable components are changed.

In the current implementation, the legion updates the version of a component whenever the system potentially writing that component is started. This is not enough for me, since I would like my scheduler to work with cyclical system dependencies.

My plan:

  • Add a new view types TrackedWrite and TryTrackedWrite (Option<TrackedWrite<T>>) to the legion. Those types will increase the component version when DerefMut::deref_mut() is called.
  • Add to the legion the ability for an external application to read the version number of a component: ChunkView::component_version<T: Component>() -> Option<u64> and ComponentSlice::version() -> u64.
  • Implement the scheduler as a separate crate.

I would like my changes to be useful for the legion and have a chance to be merged upstream.

At the moment I have changed the type of the version type in storage from UnsafeCell<u64> to AtomicU64. This is done so that TrackedWrite<T> wrappers will able to update the version in parallel from different threads.
The benchmarks show no significant performance change:

update transform/par_for_each_mut/9000 -1.3168%

I also saw comment in the code about making the version field of ComponentSliceMut private. I will try to handle this.

I would like to hear any suggestions.

Here is a branch i’m working on: GitHub - akhilman/legion at feat-change-tracking-on-deref .
I’ll make pull request when I finish.