-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Performance: Optimize monster planning #69176
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
I was wondering if using reachable zones to populate the faction map would be a win. |
Essentially your change to add the flood fill didn't actually change the algorithmic complexity of the code, it just acted as a fast O(1) check to skip much more expensive O(1) processing. The monster planner as a whole was still O(n^2) where n is number of monsters, this uses the flood fill to turn it into O(n*m) where m is number of monsters in a given zone. It's not responsible for all of the 30% time reduction (50% speed up), just the biggest part. |
Removed changes unrelated to the flood fill change. I'll PR them separately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing any improvement when waiting in the TCL from this save Yelm.tar.gz
But there's too much variance there, unrelated to monster planning.Furthermore, monster::plan()
barley registers when profiling visitable_zone_surface_test
so that's not a good benchmark either
Can you update the test or provide a stable benchmark to illustrate the gains here?
|
Sorry, I'm still not really seeing it. I had to wear a blindfold and ear plugs from your save because monsters wander into view. If there is an improvement there, it's masked by unrelated variance. A test unit would be best. Even running This is with gcc 13.2.1 and and -Og build, btw. |
I'm using a release build on windows with MSVC. Could be some compiler shenanigans. CPU is a i9-13980HX. |
Results wise, at least preliminarily, looks pretty good for me. Total cost across 3 hours was cut by about 25%. This isn't just measurement error, other baseline functions like |
This seems to be good as is for now. I have a few improvements I want to make later, but right now it is blocking #69198 which has way more impact. |
Original commit changeset: f79a631
* Use the zone floodfill to optimize monster planning algorithmic complexity. * Delete timed_event_list.output * Fix crash on game exit.
Summary
Performance "Reduced wait times in high traffic areas by ~15-20%"
Purpose of change
Waiting in TCL is slow, there were a few easy ways to make it less slow.
Describe the solution
Moved the reachability flood fill into map so it could be used in the monster planner to iterate over hostile monsters in O(monsters_in_zone) instead of O(all_monsters).
Describe alternatives you've considered
I originally was also using the zone reachability to optimize
sees
, but it ended up having no impact. I believe there are some other improvements that could be made to the zone reachability flood fill in general, but it's a pretty small part of the profile now. Worst part by far is the pathfinding.Testing
Game doesn't crash and the tests pass. PR is still being worked on.