Ticket #791 (new enhancement)
Lightweight components / reduce overhead for resources
| Reported by: | historic_bruno | Owned by: | |
|---|---|---|---|
| Priority: | Nice to Have | Milestone: | Backlog |
| Component: | UI & Simulation | Keywords: | resources |
| Cc: |
Description
One thing I've noticed with random maps, it's very easy to use large amounts of memory on maps with high resource counts (not yet noticeable on scenarios since entities must be placed individually - the limit being the designer's patience). Presumably this is because every instance of a resource has it's own component objects in memory all the time. Considering a map with thousands of trees, the waste is apparent because not even close to that many trees will be gathered at once and most of the objects will be identical anyway.
A potential solution for this is to use some sort of "lightweight" component for resources. There could be one instance, which stored changing values such as resource counts in an efficient typed array. It's not clear how easy this would be to implement or how much of a change it would require to the component system, if any.

I think the first step is to measure resource usage. Probably what'd be useful is a function that takes an entity ID and prints a list of all its components and the sizes of C++ ones (just computed as sizeof(CCmp...), probably done via the component-setup macro stuff); then maybe do something similar to the script object serialization code, except counting the approximate size of the data (i.e. assume jsvals are 8 bytes, strings are 2*length (unless they're interned strings), non-array objects are a jsval per key plus all their values, or whatever). That should give an indication of what areas could be optimised and what the expected gain is when compared to other implementations.