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

Accelerate point cloud conversion to ROS messsge #557

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

zygfrydw
Copy link

@zygfrydw zygfrydw commented Jul 8, 2021

I this merge request I have significantly accelerated point cloud conversion to ROS message.
I have noticed that create_cloud function is called with NumPy array representing points, therefore the points are already stored in a byte array in the same format as the message format.
According to documentation, the points argument can be any list of iterables, therefore I have added the helper function _check_if_fast_byte_coversion_avaliable, which checks if the fast path can be used in this case.
Most likely the create_cloud is only called with np.ndarray for points, but I am not familiar with this codebase to ensure it.

Benchmark results:

ROS Hz results before changes:

# ros2 topic hz /carla/ego_vehicle/vehicle_status -w 20
average rate: 10.965
        min: 0.086s max: 0.098s std dev: 0.00271s window: 20
average rate: 10.866
        min: 0.087s max: 0.103s std dev: 0.00326s window: 20

Benchmark of carla-bridge with py-spy

# sudo ~/.local/bin/py-spy top --pid $(pgrep bridge) --native
Total Samples 400
GIL: 69.00%, Active: 116.00%, Threads: 10

  %Own   %Total  OwnTime  TotalTime  Function (filename:line)                                                                        
 20.00%  20.00%   0.770s    0.770s   sched_yield (libc-2.31.so)
 15.00%  15.00%   0.530s    0.530s   pthread_cond_timedwait@@GLIBC_2.3.2 (libpthread-2.31.so)
  5.00%  22.00%   0.260s    0.940s   create_cloud (carla_ros_bridge/sensor.py:328)
  5.00%   5.00%   0.150s    0.150s   do_futex_wait.constprop.0 (libpthread-2.31.so)
  3.00%   3.00%   0.070s    0.070s   0x7f2941ef2a8f (numpy/core/_multiarray_umath.cpython-38-x86_64-linux-gnu.so)
  1.00%   3.00%   0.070s    0.170s   can_execute (rclpy/executors.py:446)

ROS HZ after my modifications:

# ros2 topic hz /carla/ego_vehicle/vehicle_status -w 20
average rate: 16.112
        min: 0.056s max: 0.071s std dev: 0.00347s window: 20
average rate: 16.529
        min: 0.057s max: 0.067s std dev: 0.00265s window: 20

Benchamark with py-spy after modifications

# sudo ~/.local/bin/py-spy top --pid $(pgrep bridge) --native
Total Samples 400
GIL: 69.00%, Active: 116.00%, Threads: 10

  %Own   %Total  OwnTime  TotalTime  Function (filename:line)                                                                        
 34.00%  34.00%   13.78s    13.78s   sched_yield (libc-2.31.so)
 14.00%  14.00%    8.52s     8.54s   pthread_cond_timedwait@@GLIBC_2.3.2 (libpthread-2.31.so)
  2.00%   2.00%    1.68s     1.68s   do_futex_wait.constprop.0 (libpthread-2.31.so)
  0.00%   0.00%    1.07s     1.07s   0x7f26641086c3 (libc-2.31.so)
  2.00%   2.00%   0.890s    0.890s   syscall (libc-2.31.so)
  2.00%   2.00%   0.870s    0.900s   __add__ (rclpy/waitable.py:42)
  0.00%   0.00%   0.700s    0.790s   __add__ (rclpy/waitable.py:40)

This change is Reviewable

@joel-mb joel-mb self-assigned this Sep 16, 2021
@AzaelCicero
Copy link

@joel-mb Who else can review this change in order to get it merged?

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.

3 participants