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 inbounds #27825

Merged
merged 3 commits into from
Jan 24, 2019
Merged

Conversation

kevingranade
Copy link
Member

@kevingranade kevingranade commented Jan 24, 2019

Summary

SUMMARY: Performance "Optimize inbounds check and reactor lookup."

Purpose of change

Did some profiling, these two methods came up at the tippy top of the profile when spending a lot of time waiting or sleeping.

Describe the solution

generic_inbounds was creating and destroying a ton of tripoint objects while summing coordinates, so extracted the math to just sum integer values instead.
map::inbounds was also doing a lot of math to create it's bounding boxes since it took my_MAPSIZE as an input. Created a second inbounds method for tinymap so that each variant could use a compile-time constant value.
Vehicle code was spending a lot of time checking wether parts were reactors, so I added reactors to the list of flags cached in a bitset.

Describe alternatives you've considered

First I made the inbounds check templated, but it looks like that didn't help significantly, the real issue was the operations used and the excessive tripoint creation.

Impact

These methods accounted for roughly 30% of the execution time when the game was running in fast forward mode (waiting, crafting, sleeping). These changes should make long-action processing roughly 50% faster.

src/map.cpp Outdated Show resolved Hide resolved
@ZhilkinSerg ZhilkinSerg added Code: Performance Performance boosting code (CPU, memory, etc.) Vehicles Vehicles, parts, mechanics & interactions [C++] Changes (can be) made in C++. Previously named `Code` labels Jan 24, 2019
@ZhilkinSerg ZhilkinSerg self-assigned this Jan 24, 2019
Co-Authored-By: kevingranade <kevin.granade@gmail.com>
@ZhilkinSerg ZhilkinSerg merged commit a8f1cdf into CleverRaven:master Jan 24, 2019
@ZhilkinSerg ZhilkinSerg removed their assignment Jan 24, 2019
@kevingranade kevingranade deleted the optimize-inbounds branch February 17, 2019 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Performance Performance boosting code (CPU, memory, etc.) Vehicles Vehicles, parts, mechanics & interactions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants