Skip to content

Optimised pathfinding memory and cpu usage - #276

Merged
sven-n merged 4 commits into
masterfrom
optimize-pathfinding
Oct 16, 2022
Merged

sven-n merged 4 commits into
masterfrom
optimize-pathfinding

Conversation

@sven-n

@sven-n sven-n commented Oct 16, 2022

Copy link
Copy Markdown
Member

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.

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
@sven-n
sven-n merged commit 8ac2bca into master Oct 16, 2022
@sven-n sven-n changed the title Optimized pathfinding memory and cpu usage Optimised pathfinding memory and cpu usage Oct 16, 2022
@sven-n
sven-n deleted the optimize-pathfinding branch October 16, 2022 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant