Speedup (~60%) inflation layer update#525
Speedup (~60%) inflation layer update#525mikeferguson merged 6 commits intoros-planning:indigo-develfrom
Conversation
…g cells to inflate split by distance from the closest obstacle
|
Any problem on merging this? I think I fixed the failed check in the second commit (doesn't a new commit re-trigger the testing? |
|
it should re-trigger testing, I believe. Looking at the compilation output I found this error, which should be the cause of the failure: |
|
Thanks @procopiostein. I added c++11 to the CMakeLists.txt, so using '>>' on templates should be fine. Maybe this header file used somewhere else where it is compiled with c++98? Anyway, I will just modify the PR by now so it gets merged. |
|
Thanks @jasonimercer, nice analysis. |
|
C++11 is definitely going to hold up merging this -- if you can get rid of that, I can prioritize testing and merging |
|
Also breaks the ABI compatibility probably. I don't think you can get around that. :/ |
|
@mikeferguson, back to C++03 |
|
That last commit f8d5aa4 is a bugfix for a bug which is also present in c++11 version? |
|
Yes. Confirmed with a little test program: |
|
and for the C++11 version of the above snippet: it again gives unexpected (but different unexpected) results. The differences seem to be related to how the termination condition is hoisted. |
|
@jasonimercer, thanks for the analysis. Interestingly enough, the code using both iterators and C++11 vector traversing worked, but using iterators makes test crash, hence the second commit. Till now I thought that inserting in a vector doesn't invalidate iterators, but clearly that's not the case. |
|
The above snippets actually work if you only push back a single value as that does not trigger a resize (updated size still fits in vactor capacity). Valgrind doesn't even complain. When a resize happens the iterator is now stomping through memory no longer related to the vector. If I had a .reserve(big_number) then the iterator version works as intended (until you exceed big_number). The C++11 foreach syntactic sugar still hoists the termination condition and outputs 0 1 2 rather than 0 1 2 5 5 5. Either way, good catch on the bug fix. |
|
Something else blocking merge? |
|
@corot -- I'm currently out of the office, but I will look into testing this early next week. |
|
any updates on status of this PR? |
|
We have been using costmaps with this change for several months without problem, and the speedup is really welcomed, so I would encourage merging this PR asap |
|
+1 |
|
This looks good to me, although I'm not sure whether the CellData changes break ABI, and/or whether we should care. 👍 |
|
I'd have another suggestion. Here you could, instead of using push_back (which is a really costly operation) iterate beforehand to determine the size of the vector and then use reserve() or resize(), like: Btw. How about merging this, anyway? |
|
Iterating over the memory twice also has a price and adds more lines of code for someone new to reason about. This can be sped up down the road when C++11 is allowed and we can use move semantics. I'd suggest either merging this PR as-is or closing it. It's high quality, free work by the community given to ROS. ROS should not string contributors along for 9 months. |
|
@mikeferguson , is there anything stopping this merge? Is there anything we can do to help? |
|
@procopiostein I really just need to sit down and test it. Should have time to do that over the next week, trying to do a big scrub of open issues/PRs (I know they've been piling up for a while) At the end of the day, we're not trying to "string contributors along" -- but we do have day jobs that don't always allow a bunch of time for testing/development. While I'd love to merge lots of new features/improvements quickly, we also have to weigh the fact that when something in navigation breaks (particularly costmaps), real world damage can occur (robots hit stuff). This particular PR drastically changes a core function, and is targeted at an LTS release that was already 2+ years into that 5 year life cycle when the PR was created. |
|
@mikeferguson thanks for the feedback. I do understand that this is a very delicate PR and it takes a lot of your free time to check it properly. Sorry if it felt I was pressing you in any way, that was not my intention. |
|
@procopiostein -- I should have been more clear there -- my first paragraph was responding to your question, but my second paragraph was more general towards the set of the comments that came before yours. I also didn't specifically answer your question though: one thing you can do to help this PR along would be if you have tested this specific PR on a particular robot platform (real or simulated) please let us know by posting a comment here. It would help to know which robot and which navigation configuration package (if publicly available, please post a link to it). There are many robots running the navigation stack these days, and far more parameters than we can possibly test all combinations, so knowing that something has been tested on a wide set of platforms helps. |
|
Thanks for the explanation, @mikeferguson. I really understand how busy core maintainers are. If this helps, I can PR this on kinetic and/or lunar, so we don't risk our venerable indigo. In any case, we have been using the modified costmaps for almost a year without problems, and in fact got rid off issue #584 that used to happen once in a while before. |
|
@corot -- there are still a ton of robots running Indigo -- and it sounds like we do have a bunch of testing going on around this, so I think the community would really like it to go into indigo. We've let it sit here for 9 months -- let me dig into it closer over the next couple days. |
|
@mikeferguson - As a general remark, I understand how hard it is to find time for maintenance like this, but maybe you could use some help 'hiring' more people for that purpose? It would be a great help for the whole community. |
|
I did some testing with a real PMB2 robot, running ros indigo and ubuntu 14.04, comparing corot:faster_costmap branch against version 1.12.13. |
|
@mikeferguson, sorry I spoke harshly. I know you guys are also contributing your time to manage these repos and keeping the ROS stack stable. I really appreciate all the work you put into it. I just need to recalibrate for upstream and realise that a 2 day old PR isn't "getting old" : ) |
|
Ok, tested in several hardware configurations here, code looks good. Going to squash-merge for ease of forward port to K+L |
* Replace the priority_queue used on inflation layer by a map containing cells to inflate split by distance from the closest obstacle * Update inflation test to match previous change
* Replace the priority_queue used on inflation layer by a map containing cells to inflate split by distance from the closest obstacle * Update inflation test to match previous change
* Replace the priority_queue used on inflation layer by a map containing cells to inflate split by distance from the closest obstacle * Update inflation test to match previous change
* Replace the priority_queue used on inflation layer by a map containing cells to inflate split by distance from the closest obstacle * Update inflation test to match previous change
|
Hi all Has this speedup on inflation layer update implemented in ROS Noetic navigation stack deb? Best, |
hello samuel, I have the same question in ros melodic version!!! anyone can reply? |
|
Currently these features only available on ROS2. Best, |
Th initial 60% yes, both in melodic and noetic. The additional 25% only in ROS2, as @HappySamuel says |
|
ok, thx!!! I will try it~ |
* Section 1: docker * docker images * done * words * fromatting * formatting * rename conclusions * formatting * formatting * fixing * nice detail * Update tutorials/docs/docker_dev.rst Co-authored-by: Ryan <ryanfriedman5410+github@gmail.com> * Update tutorials/docs/docker_dev.rst Co-authored-by: Ryan <ryanfriedman5410+github@gmail.com> * Update tutorials/docs/docker_dev.rst Co-authored-by: Ryan <ryanfriedman5410+github@gmail.com> * Update tutorials/docs/docker_dev.rst Co-authored-by: Ryan <ryanfriedman5410+github@gmail.com> * Update tutorials/docs/docker_dev.rst Co-authored-by: Ryan <ryanfriedman5410+github@gmail.com> * Update tutorials/docs/docker_dev.rst Co-authored-by: Ryan <ryanfriedman5410+github@gmail.com> * adding ryan suggestions * fix container * links * line * prefix * prefix --------- Co-authored-by: Ryan <ryanfriedman5410+github@gmail.com>

Following this discussion, the pop in the priority_queue used for sorting the cells to inflate takes a lot of CPU. I replaced it by a map containing cells to inflate split by distance from the closest obstacle.
I have played around with the changes for a while, and it seems to work fine, also scaling well to higher resolutions and inflation radius. After profiling my changes, the new biggest CPU eater is the map lookup for distances on enqueue method. Maybe someone with better understanding of STL containers can give an extra speedup, knowing this.
I require C++11. Hope it's not an issue for indigo code.