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

Cache mutation trait flags #77671

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

CLIDragon
Copy link
Contributor

Summary

Performance "Cache mutation trait flags"

Purpose of change

has_trait_flag took up ~7% of CPU time. It has been reduced to ~1.7%.

Describe the solution

Implement a cache for mutation flags in Character. The implementation was copied from the already existing bio_flag_cache.

Describe alternatives you've considered

None.

Testing

Game runs normally.

Additional context

The cache is very conservative, and is reset for any change to the
player's mutations.
@github-actions github-actions bot added Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies [C++] Changes (can be) made in C++. Previously named `Code` Character / World Generation Issues and enhancements concerning stages of creating a character or a world Code: Performance Performance boosting code (CPU, memory, etc.) json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Nov 8, 2024
@PatrikLundell
Copy link
Contributor

A word of caution: adding more data to Character means it takes longer to load or create each Character variable throughout, so it's a net profit only if the reduced access cost for these flags adds up to more than the losses due to the increased weight of Character. The profits on access are easy to make, while the losses are diffuse, and so are hard to quantify. I have no sense of whether it is a problem in this case or not, however.

@CLIDragon
Copy link
Contributor Author

A word of caution: adding more data to Character means it takes longer to load or create each Character variable throughout, so it's a net profit only if the reduced access cost for these flags adds up to more than the losses due to the increased weight of Character. The profits on access are easy to make, while the losses are diffuse, and so are hard to quantify. I have no sense of whether it is a problem in this case or not, however.

I expect the extra memory cost would be around a dozen JSON flags per Character, which is very small proportional to their current size, while the benefits are large.

@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Nov 8, 2024
@Maleclypse Maleclypse merged commit 5fd7937 into CleverRaven:master Nov 10, 2024
22 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Character / World Generation Issues and enhancements concerning stages of creating a character or a world Code: Performance Performance boosting code (CPU, memory, etc.) json-styled JSON lint passed, label assigned by github actions Mutations / Traits / Professions/ Hobbies Mutations / Traits / Professions/ Hobbies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants