# Implementing a new performant Entity Component System (ECS). (Please request the features you want)

**URL:** <https://discourse.julialang.org/t/implementing-a-new-performant-entity-component-system-ecs-please-request-the-features-you-want/99109>\
**Category:** Package Announcements\
**Created:** [May 19, 2023, 12:16pm UTC](https://discourse.julialang.org/t/implementing-a-new-performant-entity-component-system-ecs-please-request-the-features-you-want/99109 "2023-05-19T12:16:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarny\_GG\_Channie](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Post date:** [May 19, 2023, 12:16pm UTC](https://discourse.julialang.org/t/implementing-a-new-performant-entity-component-system-ecs-please-request-the-features-you-want/99109/1 "2023-05-19T12:16:27Z")

</div>

Julia provides a good compile-time dispatch, however, when a run-time dispatch is required, Julia is not so fast. While [Overseer](https://github.com/louisponet/Overseer.jl) provides a possible solution, it is about updating an entire system at a time, and while it may be performant for similar algorithms, getting all entities in, for example, a || b && c requires some union/intersection. In contrast, this library will focus on determining the behavior of individual entities with a complex combination of traits in a performant manner.

So, here’s how this ECS will work.  
It will store traits as 64-bit integers (Higher than this and it will error out. 64 is a hard limit because of the number of bits in a 64-bits integer.) It will mask out the irrelevant bits in each lookup and then perform a perfect hash to look up the result from a lookup table. The result could be a wrapped function from [FunctionWrappers](https://github.com/yuyichao/FunctionWrappers.jl), a boolean, a number for if/else (for a small number of choices), a function parameter, a callable object, a 3x3 matrix, etc…

Basic features such as looking up individual bits will be implemented. There are several tricks you can do with this technique such as joining traits from different entities using “OR” instruction and so on. Request your feature here as I am implementing it.  
The implementation is [here](https://github.com/AliceRoselia/Arceus.jl) and is still incomplete.  
Please make a feature request here so I can improve it.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [May 19, 2023, 3:53pm UTC](https://discourse.julialang.org/t/implementing-a-new-performant-entity-component-system-ecs-please-request-the-features-you-want/99109/2 "2023-05-19T15:53:38Z")

</div>

What’s an ECS?

---

<div class="post-metadata">

**Author:** ![DoktorMike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doktormike/32/2736_2.png) [@DoktorMike](https://discourse.julialang.org/u/DoktorMike)\
**Post date:** [May 19, 2023, 4:41pm UTC](https://discourse.julialang.org/t/implementing-a-new-performant-entity-component-system-ecs-please-request-the-features-you-want/99109/3 "2023-05-19T16:41:44Z")

</div>

It’s a software architectural pattern called Entity Component System.

---

<div class="post-metadata">

**Author:** ![Tarny\_GG\_Channie](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Post date:** [May 23, 2023, 1:57am UTC](https://discourse.julialang.org/t/implementing-a-new-performant-entity-component-system-ecs-please-request-the-features-you-want/99109/4 "2023-05-23T01:57:52Z")

</div>

Progress coming now! This project should now be at least 20% complete.

Feel free to review my code.

---

<div class="post-metadata">

**Author:** ![Tarny\_GG\_Channie](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Post date:** [July 16, 2023, 4:12am UTC](https://discourse.julialang.org/t/implementing-a-new-performant-entity-component-system-ecs-please-request-the-features-you-want/99109/5 "2023-07-16T04:12:17Z")

</div>

Update: This package is finished.

---

<div class="post-metadata">

**Author:** ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)\
**Post date:** [July 16, 2023, 7:39pm UTC](https://discourse.julialang.org/t/implementing-a-new-performant-entity-component-system-ecs-please-request-the-features-you-want/99109/6 "2023-07-16T19:39:32Z")

</div>

I would like to play around with this a bit but I don’t understand how the package works. What takes the role of an entity, component and system here? I’m guessing `@trait` defines a component, `@traitpool` defines something like Overseers ledger, `@make_traitpool` defines a name for an entity, `@settraits` sets values for an entity and `@lookup` is related to systems? Or maybe `@subpool`? Adding more documentation and example that shows off a minimal setup would be very helpful.

A comparison between this and Overseer could also be quite useful. What are the things this does better? What’s worse? How does the syntax compare?

You’re missing an import + dependency on Random btw, and one of the macros seems to be doubly defined:

```julia
WARNING: Method definition @subpool(LineNumberNode, Module, Any, Any) in module Arceus at .../Arceus/src/trait_pool.jl:20 overwritten at .../Arceus/src/subpool.jl:80.

```

---

<div class="post-metadata">

**Author:** ![Tarny\_GG\_Channie](https://avatars.discourse-cdn.com/v4/letter/t/3bc359/32.png) [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Post date:** [July 16, 2023, 11:27pm UTC](https://discourse.julialang.org/t/implementing-a-new-performant-entity-component-system-ecs-please-request-the-features-you-want/99109/7 "2023-07-16T23:27:32Z")

</div>

Fixed the random dependency. I will add more documentation later. Thank you for your nice feedback. This is my first package and I believe I would’ve done it much better if I had done it again.
