Skip to content
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

speeding up of app load: 40 seconds -> 4 seconds #52

Merged
merged 6 commits into from
Mar 17, 2022

Conversation

knorth55
Copy link
Contributor

@knorth55 knorth55 commented Dec 25, 2021

UPDATE: I update this PR to speed up more.

Loading apps takes long time, which drops my productivity.
I change not to use roslib.packages.find_resource for speed up.
I change to share the same rospack object between multiple functions to make roslib.packages.find_resource faster.

Current kinetic-devel takes 39 seconds to load 12 app.
This PR reduces it to 4 seconds.

kinetic-devel branch

[ERROR] [1640440511.654021]: total time: 39.4751198292

cProfile output

         67248708 function calls (62972939 primitive calls) in 39.464 seconds

   Ordered by: cumulative time

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000   39.463   39.463 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app_list.py:215(update)
        1    0.000    0.000   39.462   39.462 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app_list.py:167(_load)
       14    0.000    0.000   39.451    2.818 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app_list.py:122(update)
        7    0.000    0.000   39.451    5.636 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app_list.py:93(__init__)
        7    0.000    0.000   39.451    5.636 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app_list.py:101(_load)
       25    0.000    0.000   39.431    1.577 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app.py:306(load_AppDefinition_by_name)
      100    0.041    0.000   39.352    0.394 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app.py:117(find_resource)
      100    0.002    0.000   39.310    0.393 /opt/ros/melodic/lib/python2.7/dist-packages/roslib/packages.py:487(find_resource)
       25    0.001    0.000   29.561    1.182 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app.py:278(load_AppDefinition_from_file)
      100    0.027    0.000   27.902    0.279 /opt/ros/melodic/lib/python2.7/dist-packages/catkin/find_in_workspaces.py:95(find_in_workspaces)
    12148    0.062    0.000   27.395    0.002 /usr/local/lib/python2.7/dist-packages/catkin_pkg/packages.py:75(find_packages)
    12148    0.084    0.000   27.324    0.002 /usr/local/lib/python2.7/dist-packages/catkin_pkg/packages.py:112(find_packages_allowing_duplicates)
    12148    1.674    0.000   25.028    0.002 /usr/local/lib/python2.7/dist-packages/catkin_pkg/package.py:583(parse_package_string)
4152808/188764    4.308    0.000   11.479    0.000 /usr/lib/python2.7/copy.py:145(deepcopy)
      100    0.000    0.000   11.206    0.112 /usr/lib/python2.7/dist-packages/rospkg/rospack.py:199(get_path)
      100    0.117    0.001   11.205    0.112 /usr/lib/python2.7/dist-packages/rospkg/rospack.py:173(_update_location_cache)
    32500    0.863    0.000   11.088    0.000 /usr/lib/python2.7/dist-packages/rospkg/rospack.py:49(list_by_path)
   188764    1.031    0.000    9.937    0.000 /usr/lib/python2.7/copy.py:306(_reconstruct)
       25    0.000    0.000    9.837    0.393 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app.py:191(_AppDefinition_load_interface_entry)
       25    0.000    0.000    9.836    0.393 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app.py:153(_AppDefinition_load_icon_entry)
       25    0.000    0.000    9.832    0.393 /home/knorth55/ros/vive_ws/src/PR2/app_manager/src/app_manager/app.py:174(_AppDefinition_load_launch_entry)
   377528    1.017    0.000    7.454    0.000 /usr/lib/python2.7/copy.py:234(_deepcopy_tuple)
     6472    0.296    0.000    5.672    0.001 /usr/local/lib/python2.7/dist-packages/catkin_pkg/package.py:115(__getattr__)
327164/163962    0.888    0.000    5.613    0.000 /usr/lib/python2.7/os.py:209(walk)

This PR

[ERROR] [1640619177.785652]: total time: 4.10533118248

@knorth55
Copy link
Contributor Author

knorth55 commented Dec 25, 2021

I update this PR, and now it only takes 1 seconds to load the app definition.

@708yamaguchi can you check this PR in your PC and report how fast it is?

@knorth55 knorth55 changed the title do not use roslib.packages.find_resource for speed up speeding up app load: 40 seconds -> 1 second Dec 25, 2021
@knorth55 knorth55 changed the title speeding up app load: 40 seconds -> 1 second speed up of app loading: 40 seconds -> 1 second Dec 25, 2021
Copy link
Contributor

@708yamaguchi 708yamaguchi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is very useful PR.

I have 619 ROS packages in my workspaces,

$ rospack list | wc -l
619

and I have 18 apps in 4 packages in my workspaces.

[INFO] [1640495997.563157]: 1 apps found in /home/leus/ros/melodic/src/jsk-ros-pkg/jsk_pr2eus/pr2eus_tutorials/apps/app.installed
[INFO] [1640495999.662914]: 2 apps found in /home/leus/ros/melodic/src/jsk-ros-pkg/jsk_robot/jsk_robot_common/jsk_robot_startup/apps/robot_apps.installed
[INFO] [1640496012.381850]: 12 apps found in /home/leus/ros/melodic/src/jsk-ros-pkg/jsk_robot/jsk_fetch_robot/jsk_fetch_startup/apps/fetch_apps.installed
[INFO] [1640496015.567683]: 3 apps found in /home/leus/ros/melodic/src/jsk-ros-pkg/jsk_robot/jsk_pr2_robot/jsk_pr2_startup/apps/pr2_apps.installed

Without this PR,

35818241 function calls (33742020 primitive calls) in 19.040 seconds
[ERROR] [1640496024.228704]: total time: 27.6996641159 

With this PR,

478007 function calls (462837 primitive calls) in 0.423 seconds
[ERROR] [1640495916.035495]: total time: 0.429724931717

src/app_manager/app.py Outdated Show resolved Hide resolved
src/app_manager/app.py Outdated Show resolved Hide resolved
Copy link
Member

@v4hn v4hn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test any of this but now the changes make sense looking at the source code.
Please review and merge @k-okada .

@knorth55 knorth55 changed the title speed up of app loading: 40 seconds -> 1 second speed up of app loading: 40 seconds -> 4 seconds Dec 31, 2021
@knorth55 knorth55 changed the title speed up of app loading: 40 seconds -> 4 seconds speeding up of app loading: 40 seconds -> 4 seconds Feb 8, 2022
@knorth55 knorth55 changed the title speeding up of app loading: 40 seconds -> 4 seconds speeding up of app load: 40 seconds -> 4 seconds Feb 8, 2022
@Affonso-Gui
Copy link
Contributor

@k-okada Kindly ping

@k-okada k-okada merged commit debed0f into PR2:kinetic-devel Mar 17, 2022
@knorth55 knorth55 deleted the speedup-app-load branch March 17, 2022 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants