Optimize RPG::MoveCommand?
Most move commands are just a single 1 byte integer index. Our RPG::MoveCommand contains 4 int32_t's and a std::string. On amd64 linux, sizeof(RPG::MoveCommand) == 56. That's a 56x overhead for every move command in the vector!
For MoveCommand's, you only ever want to iterate over the list of commands from first to last. You don't need to index into a specific command so each command does not need to be the same size.
I did a quick test of just changing MoveCommand to uint8_t and loading the database. The results don't really change at all. That's to be expected as common events usually contain very few move commands.
| Game | Memory MoveCommand | Memory uint8_t | Saving |
|---|---|---|---|
| Heros Realm | 300 MB | 300 MB | Saving 0% |
| HH3 | 136.4 MB | 135.6 MB | Saving 0.5% |
I tested changing MoveCommand to uint8_t and loading the database and all maps into memory.
| Game | Memory MoveCommand | Memory uint8_t | Saving |
|---|---|---|---|
| Heros Realm | 327 MB | 327 MB | Saving 0% |
| HH3 | 158.7 MB | 157 MB | Saving 1% |
So despite the huge overhead on RPG::MoveCommand it's still used sparingly enough in these games that it doesn't have much of an effect.