Slow speed when generating a URDF
captain-yoshi opened this issue · comments
It takes 40 seconds for my pc (Intel i7-7700HQ 2.8GHz) to generate a URDF containing links and joints that represent a collection of collision objects (10 shelves on top of each other). Information such as subframes is also added. There is a lot of xacro loops used. The URDF generated has a size of 500kB.
Is it normal for this process to be slow ? My xacro skills may be to blame, could xacro for loops
introduces some sort of slowdown that could be improved with #291 ?
You can run the example (xacro_scene.zip)
rosrun xacro xacro scene.urdf.xacro > scene.urdf
Wow! What a huge shelf! Unfortunately, I have to blame python's xml.dom.minidom
. I filed a PR in the past to improve the situation for Python 2.7, but they didn't accept it (not trying to risk stability): https://bugs.python.org/issue24424
Maybe the patch provided there helps you as well.
For Python 3.x, the situation is slightly better. We typically generate our URDFs once when building.
To this end xacro provides some convience cmake functions.
It's a shame they did not accept it. If I read correctly, for Python 2.7 the patch gain is 150
folds for one of the examples! Will try the patch this weekend and will report the gains I have.
Thank you for the detailed explanation and feel free to close this issue.
Just for comparison without applying patches:
Melodic | Noetic | |
---|---|---|
1 Shelf | 22 sec | 1 sec |
10 Shelf | 54 min | 34 sec |
Note: The PCs are different between Melodic and Noetic so it may be hard to compare.
Melodic: Intel i7-2600
Noetic: Intel i7-7700
Comparing timing on same machine (i7-2600) gives roughly the same table:
Melodic | Noetic | |
---|---|---|
1 Shelf | 22 sec | 1 sec |
10 Shelf | 54 min | 35 sec |
@rhaschke Trying to generate a urdf from xacro for Python 3.x (ROS Noetic) using the conveniance cmake functions. Do you have an exemple on how to do that ? Not sure if I have to uncomment parts of cmake...
Trying to generate a urdf from
xacro
using the convenience cmake functions. Do you have an example on how to do that?
Sure:
- long version: https://github.com/ros/xacro/blob/noetic-devel/test/test-xacro-cmake/CMakeLists.txt#L9-L16
- short version: https://github.com/ros/xacro/blob/noetic-devel/test/test-xacro-cmake/CMakeLists.txt#L19
See doc.
Benchmarked my Pisa tower example using a loop and an unrolled loop on Noetic (see below). It seems that looping can be quite taxing. Maybe this can be improved with #291.
Test | Time (s) |
---|---|
Loop | 28 |
Unrolled Loop | 8 |
<!-- Unrolled loop x10 -->
<xacro:shelf name="bookshelf1"
frame_id="world"
xyz="0.8 0 0"
h_board_thickness="0.02"/>
<xacro:shelf name="bookshelf2"
frame_id="world"
xyz="0.8 0 1"
h_board_thickness="0.02"/>
...
<xacro:shelf name="bookshelf10"
frame_id="world"
xyz="0.8 0 9"
h_board_thickness="0.02"/>