-
Notifications
You must be signed in to change notification settings - Fork 52
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
Caching for pathfinding #1569
Comments
This sounds nice in theory but it seems like it might be premature optimization. I am worried that the logic to invalidate the cache would be more expensive than just recomputing a path every time.
|
Well, how would we determine if the optimisations are premature? I am not sure we are using the path enough yet to make a good decision. But once we do, could we use the new counters to count path queries/etc. @kostmo? I am also interested in the simple alternatives, like keeping the original path and letting robots recalculate if they need to. |
It would be cool if we could update the shortest distance cache of A* directly and let it recompute the result. My hope is that the path metric of the algorithm would itself determine if the update is relevant. Most of your points still apply @kostmo, but I was considering if we could avoid throwing out all the work. |
I've created a demo in #1594 where I think the kind of caching I describe here would help a lot. Other than the stuttering issue, the emergent roaming/grazing behavior is quite fun to observe and could feature in various scenarios. |
#1595 implements caching and demonstrates a dramatic improvement to the roaming/grazing performance. |
@kostmo great, but isn't that measured against turning off an on navigation for each turn? 🤔 Also how is everything else affected? 😅 |
Closes #1569 ## Performance Path cache invalidation upon world modifications (i.e. entities inserted or removed) entails iterating over all of the previously-cached paths [here](https://github.com/swarm-game/swarm/pull/1595/files#r1390158411). For efficiency's sake, we avoid iterating over "all existing robots". Any scenario that does not use the `path` command is entirely unaffected by this change. ## Demo Previously, this demo was virtually unplayable, since when moving between widely-spaced "clusters" of flowers, an expensive A-star search was invoked at almost every tick. Now, the vast majority of moves utilize the cache, and the demo exhibits minimal stuttering (e.g. when a single A-star search is performed when moving between distant clusters). scripts/play.sh -i scenarios/Fun/horton.yaml --autoplay --speed 7 ### Event log An event log specific to the path cache is maintained with its own ring buffer: scripts/play.sh -i scenarios/Testing/1569-pathfinding-cache/1569-harvest-batch.yaml --autoplay and view http://localhost:5357/paths/log
To improve the performance of #836, a caching mechanism could be designed that optimizes for the common case: a robot repeatedly invokes
path
with identical arguments and follows the yielded directions precisely.path
command again with different arguments, the previous computed path shall be discarded.path
command had been invoked with the modified entity as a target)The text was updated successfully, but these errors were encountered: