Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize RPG::MoveCommand? #269

Open
fmatthew5876 opened this issue Oct 26, 2018 · 0 comments
Open

Optimize RPG::MoveCommand? #269

fmatthew5876 opened this issue Oct 26, 2018 · 0 comments

Comments

@fmatthew5876
Copy link
Contributor

fmatthew5876 commented Oct 26, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants