i'm working with the Ashley Entity-Component-System (related to libGDX) to program a server-side simulation for an online game and i stumbled upon a serious performance drawback, that is probably caused by how it manages Entity-Sets:
"Family", these are basically descriptors for Entities with a specific set of components. Removing a component is an costly operation because the Family-instance needs to search through an Array of entities that it manages and remove the Entity from that Array. This is O(n) for every single removal at worst.
And here's my problem: I have a Family that describes all Entities that do have a position and a velocity component. If i want to remove the velocity-component, for example, to turn it into an static entity and re-add it later to make it move again, this completely eats up my budget of frame time (50ms->20fps) with only ~7000 Entities changing Family back and forth within a frame. At the same time, moving 100000 entities takes only about 15ms at max (without multithreading ~30ms).
I have thought of these options yet:
-Change the data-structure that the Entities are sorted into, this creates new problems, but may still be the most viable Solution, i thought of mapping the Entity IDs to Objects or keeping them in a sorted data-structure.
-Sort everything once after a System has finished execution, requires redesigning a lot of code but probably reduces the time-consumption greatly
-Changing the Entity System, i know of Artemis, but it would be great if you could point me at something else for Java if you know a library that does it better.
-This whole thing may not even become a bottleneck when running the final game-simulation, it might or might not, so just going on and thinking about this later may be acceptable, since I'm probably over-engineering again.
What do you think is the way to go?