-
Notifications
You must be signed in to change notification settings - Fork 65
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
dramatic performance boost for consecutive rospack calls [backport to indigo] #49
Conversation
This goes along with roslib PR #97. |
@@ -331,16 +331,13 @@ Rosstackage::crawl(std::vector<std::string> search_path, | |||
{ | |||
if(!force) | |||
{ | |||
if(readCache()) | |||
// read the cache only once (when search_paths_ is still empty) | |||
if(search_paths_.empty() && readCache()) |
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.
Why do you want to prevent using the existing cache here? This will result in worse performance when this function is called multiple times.
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.
Indeed, if the current search_path has changed, we should read the corresponding cache. I adapted the code, such that there are the following code paths in Rosstackage::crawl() now:
- crawling is enforced -> just (re)crawl
- current search_path matches previous one and rospack already crawled: nothing todo [new]
- current search_path diverges from previous one: read corresponding cache
- on success: nothing else todo
- on failure (no cache or too old): re-crawl
- on re-crawling, set the search_paths_ appropriately
@dirk-thomas Did you already have seen my answers to your remarks? |
return false; | ||
} | ||
return true; | ||
} |
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.
How is this function different from the comparison operator of a vector (http://en.cppreference.com/w/cpp/container/vector/operator_cmp)?
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.
Valid point. I didn't checked for availability of vector::operator==
. Simply moved the existing verbose code into its own function. Now, the function is replaced by std::vector::operator==
.
I've started working on this in two branches: https://github.com/ros/ros/tree/reuse_cache I applied @rhaschke's changes and added a test to rospack to test the effect of in-process changes to Sadly, that test passes on the first run, but fails on the second run and all subsequent runs. I'm still looking into it. |
Hm. I tested that only manually. I will have a look into your branch too. |
I had some issues to compile the unit test. Using my catkin tools environment, the binary rospack-utest wasn't created by default. I had to manually |
Thanks for fixes in #52. But I still have failures elsewhere after the initial run, apparently related to whether the cache is available:
|
To build and run the test (assuming you have a workspace
You can also run all the tests via |
Here's more detail, with some instrumentation added to the test:
Looks like the result from the first run, with one setting for @rhaschke, can you look into this and get back when it's working? |
Yes, of course. I will do it. |
readCache() simply add more stackages without clearing the list of |
Thanks for the fixes in #53. I'll open a new PR now. |
The cache itself was valid. However, reading the cache simply added new |
d805a22
to
cf34b95
Compare
readCache if search paths have changed
readCache should clear stackages_ before adding more added new method clearStackages(), used in three locations
cf34b95
to
5f65a89
Compare
I rebased onto the same indigo-devel commit from where #54 started. Subsequently I rebased all additional commits in #54 onto this original PR to keep proper history (see comments here). |
@dirk-thomas, @gerkey |
We discussed this today and agree that it should be merged into jade, then depending on whether there are any problems, we'll consider backporting to indigo. |
@ros-pull-request-builder test this please |
This patch has been merged into the newly created If there are no regressions it will be considered for being backported into |
I have updated the issue title that only the backport is pending. |
Since this has been released into Kinetic as well as Jade for a while without any regressions I cherry-picked the change to the indigo-devel branch as well: 2ce1584 It will be part of the next patch release for Indigo. |
Consecutive calls to the rospack library, e.g.
ros::package::getPath()
, from within the same process recrawled theROS_PACKAGE_PATH
all the time, because the appropriate rospack instances were created again and again.This PR (going in line with a similar PR on roslib) improves things in two respects:
rospack::Rospack
instance is used inROSPack::run()
, thus re-using the same instance for all consecutive callsRosstackage::crawl()
the cache is loaded only once at the beginning, whensearch_paths_
is still emptyThe following simple test program (doing 3000 calls to
getPath()
) performs 160 times faster: