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

Eliminate unecessary monster enumeration #32215

Merged
merged 1 commit into from
Jul 7, 2019

Conversation

kevingranade
Copy link
Member

Summary

SUMMARY: Performance "Avoid unecessarally enumerating monsters."

Purpose of change

This operation scales as O(n^2) in the number of monsters on the map, meaning with enough monsters it dominates all other computation.

Describe the solution

Only enumerate the monsters if we need to, which is when a monster has a need to size up other monsters.

Describe alternatives you've considered

There are potentially ways to either cache this list or make it much cheaper to produce, but I want to wait on a demonstrable need to dive into that kind of thing.

Additional context

To trigger, give the player invincibility, and debug spawn monsters with a large radius (I used 50). Radius 50 gives a bit over 10,000 monsters on the map. The symptom is single turns taking multiple seconds to resolve.

This operation scales as O(n^2) in the number of monsters on the map, meaning with enough monsters it dominates all other computation.
@ZhilkinSerg ZhilkinSerg 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 Jul 7, 2019
@ZhilkinSerg ZhilkinSerg merged commit 2ff7a1b into master Jul 7, 2019
@kevingranade kevingranade deleted the kevingranade-eliminate-monster-enumeration branch July 8, 2019 19:27
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.

2 participants