Repository navigation
Optimised pathfinding memory and cpu usage - #276
Merged
Merged
Conversation
First, the path finding itself was optimized to only search in a path in a scoped area of a map. For the most searches, a 8x8 field is enough. In the cases where it's not, the field is extended to 16x16. Before this optimization, the whole map of 256x256 was used, which took considerable memory and initialization time. Next, I implemented pooling for the pathfinder objects. Before, the monster instances each had one instance of a PathFinder object. However, they use it pretty infrequently - even when players are around, just every few seconds. This had a very negative effect on the memory usage. Since a search for a path doesn't need a lot of time - in release build and with optimization above, averaging at just 0,025 ms! - very few PathFinder objects can serve thousands of monsters.
When no path was found, just move randomly. You could watch the difference in the lost tower 1 map, where there are long walls. There you can see monsters behind these walls. Previously, they couldn't find a path and just didn't move at all. Now, these monsters move randomly - giving a more dynamic player experience.
Made segment size determination more dynamic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First, the path finding itself was optimized to only search in a path in a scoped area of a map. For the most searches, a 8x8 field is enough. In the cases where it's not, the field is extended to 16x16. Before this optimization, the whole map of 256x256 was used, which took considerable memory and initialization time.
Next, I implemented pooling for the pathfinder objects. Before, monster instances each had one instance of a PathFinder object. This had a very negative effect on the memory usage. However, they use it pretty infrequently - even when players are around, just every few seconds. Since a search for a path doesn't need a lot of time - in release build and with optimization above, averaging at just 0,025 ms on my machine - very few PathFinder objects can serve thousands of monsters.
Finally, I added some metrics, which can be viewed on prometheus (see distributed deployment), for example.