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

Improve performance of Character::update_bodytemp #50735

Merged

Conversation

anothersimulacrum
Copy link
Member

Summary

None

Purpose of change

Character::update_bodytemp always shows up decently high when I profile. Make it faster.
Thanks to BN for pointing these out: cataclysmbnteam/Cataclysm-BN#774

Describe the solution

Profile, apply fixes, profile more. Fixes are described in each commit.

Describe alternatives you've considered

Instead of both stashing the armor per BP and changing the various functions to give info for all body parts, doing only one.

Just armor optimization:
image
image
4f63583

Just bp optimization:
image
image

Testing

Heat radiation:
image
image

Both armor and bp:
image
image

Fixing the check for CLIMATE_CONTROL:
image
image

Not checking for fire armor if no blisters:
image
image

Additional context

I was going to include an EOC perf improvement here too, but it's more complicated, and leaving it out probably makes it slightly easier for the BN people to grab this.

@actual-nh actual-nh added [C++] Changes (can be) made in C++. Previously named `Code` Code: Performance Performance boosting code (CPU, memory, etc.) Mechanics: Character / Player Character / Player mechanics Mechanics: Temperature Freezing, cooling, thawing, heating, etc. mechanics labels Aug 13, 2021
Cache a variable, use the already fetched maptile to check the terrain
at the tile instead of looking up the submap again.
Perform two optimizations on Character::bodytemp
1. Store the items worn on each bodypart, and refer to that instead of
   iterating through all worn items and selecting the ones for the
   relevant body part multiple times.
2. Adjust some functions to run once, and return the data for all body
   parts. This optimization has a fair bit of overlap with CleverRaven#1, but I
   think both have value

There should be no behavioural changes.
Don't check every item for a flag for every item the character is
wearing, just check the current flag.
Character::in_climate_control drops off the profile of
Character::bodytemp with this change.
The vast majority of the time, we won't have any blisters - so only go
through the mildly expensive process of getting fire armor when we have
blisters.
@kevingranade kevingranade merged commit 7f17f94 into CleverRaven:master Aug 13, 2021
@anothersimulacrum anothersimulacrum deleted the perfing-down-the-house branch August 13, 2021 21:03
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.) Mechanics: Character / Player Character / Player mechanics Mechanics: Temperature Freezing, cooling, thawing, heating, etc. mechanics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants