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

Speedup item::best_pocket ~100% (2x as fast) and misc other wins too #55070

Merged
merged 1 commit into from
Feb 4, 2022

Conversation

akrieger
Copy link
Member

@akrieger akrieger commented Feb 3, 2022

Summary

None

Purpose of change

Profiling of unit tests (esp starting_items) after recent changes from @BrettDong showed some weird inefficiencies. Besides the usual stdlib inefficiencies with copying instead of moving or referencing, there was what looked like a glaring 2x issue in best_pocket. Code at the top was calling can_contain( it ) and exiting 'early' if it returned false. That function essentially just loops through all the contents calling can_contain( it ) on each one. That is not cheap, though, and the subsequent loop repeats basically the same calls on the same contents but with more logic around it. This doesn't seem like a true fast early exit, just wasted cycles, and accounts for ~15-20s out of 240s of test runtime for starting_items tests. Plus it's live code.

Describe the solution

Delete the probably redundant can_contain( it ) call. Fix some list insert calls to be splices, and use a reference to a std::map instead of a copy when calling made_of().

Describe alternatives you've considered

Testing

Tests still pass.

Additional context

After/Before of starting_items test with these changes @ 100 samples/second shows ~1800 sample reduction in test runtime, basically all from Character::migrate_items_to_storage without cost shift to elsewhere.
image

@github-actions github-actions bot added json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions labels Feb 3, 2022
@Maleclypse Maleclypse added the Code: Performance Performance boosting code (CPU, memory, etc.) label Feb 3, 2022
@github-actions github-actions bot added the BasicBuildPassed This PR builds correctly, label assigned by github actions label Feb 3, 2022
@kevingranade kevingranade merged commit e514109 into CleverRaven:master Feb 4, 2022
@akrieger akrieger deleted the itemization branch February 4, 2022 04:00
@NetSysFire NetSysFire added the [C++] Changes (can be) made in C++. Previously named `Code` label Feb 4, 2022
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` Code: Performance Performance boosting code (CPU, memory, etc.) json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants