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

Trivial: minor speedup of monster->Character attitude calculation #45421

Merged

Conversation

Aivean
Copy link
Contributor

@Aivean Aivean commented Nov 15, 2020

Summary

SUMMARY: Performance "Minor speedup monster->Character attitude calculation"

Purpose of change

Currently monster::attitude( const Character *u ) requests and iterates Character mutation list twice.
This may waste some CPU cycles when player has lots of mutations or there are lots of NPCs around.

Describe the solution

Request character mutation list only once.

Describe alternatives you've considered

Use "observer"-like pattern to iterate character mutations without construction of the vector. However, in this case it might be an overkill, as usually characters don't have too many mutations.

Testing

Checked that game compiles and loads.

Additional context

Before:
image

After:
image

@anothersimulacrum anothersimulacrum added [C++] Changes (can be) made in C++. Previously named `Code` Code: Performance Performance boosting code (CPU, memory, etc.) Monsters Monsters both friendly and unfriendly. labels Nov 15, 2020
src/monster.cpp Outdated Show resolved Hide resolved
Co-authored-by: anothersimulacrum <anothersimulacrum@gmail.com>
@ZhilkinSerg ZhilkinSerg merged commit 01d2bf5 into CleverRaven:master Nov 15, 2020
@Aivean Aivean deleted the monster-character-attitude-perf branch November 21, 2020 01:51
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.) Monsters Monsters both friendly and unfriendly.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants