Bacon2D/Bacon2D

Performace problems

adderly opened this issue · 4 comments

There are many places where Bacon2D can be optimized, before rushing into "solve/improve" some code it is better to point those things here.

** Things measured and in need for improvement **

  1. The Layer class has at least 50% of the code in Entity, along the same interfaces for interaction with the update loops. Could be wise to make Layer inherit Entity, which will delete some code and introduce a boost in update loops Scene.update for example.
  2. Entity uses QTime in it's update() function which is a performance kill when calling QTime.restart(), having a lot of entities will denote the speed hole. I know it is used for flexibility but it is placed in a critical part so there is no way of evading the performance drag.
  3. Scene.update call Scene.updateEntities which is an unnecesary call, should be deleted.
  4. Entity always updates, there is no way to stop a specify Entity from updating its behavior, which is more like a intuitive thing: You may found yourself using Entity.setEnabled(false) and expecting to pause its execution, in reallity all the items in the Scene are being updated all the time.
  5. Bacon2D uses childItems from QQuickItem to update its Entities, but by doing that they iterate over all the properties inside that specific Entity even if nothing is done to it. It would be better to centralize all Entity's update in the Scene update, taking into account the state of the Entity of course. This will reduce execution time as well as some memory savings.

** Wishy/Washy Alternatives **

  • I would like to have faster Behaviors, is there any faster way to achieve this?
  • Settings could be make async to have a faster startup time.

@kenvandine i might be able to tackle some of these problems but i have too many things at the time.
If you anyone is gonna make changes, just let us know here so that no double work is done.

@kenvandine Any ideas for optimizing the QTime usage in the Entity's update?
I was thinking into batching each Entity based in the update interval they have.

For example, all entities with 60 as interval will be batched together. That is a great deal of processing time saved, the thing would be to handle them from a centralized location. EX: Scene::update().

@adderly We've talked about having an EntityManager which could keep track of all the entities in the game and their states. This could be used to keep track of all the intervals and call update as needed. I've debated if the performance improvement would be worth it, but in thinking about the update interval, it probably would be.

@adderly More specifically, instead of iterating over the children looking for entities, the EntityManager could maintain a list of all entities. The list could even be a map or some other data structure so we could quickly check things like update interval, etc.