Skip to content

perf: optimize Reeds-Shepp path planning with NumPy vectorization #1242

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fishyy119
Copy link

@fishyy119 fishyy119 commented Jun 24, 2025

Summary

This PR optimizes the Reeds-Shepp path planning module by leveraging NumPy's vectorized computations. The built-in test function in reeds_shepp_path_planning.py was executed 100 times to benchmark performance. The runtime improvements of key functions are as follows:

Function Before Optimization (s) After Optimization (s) Relative Time (%)
calc_paths 6.4861 0.2676 4.13%
generate_local_course 2.3774 0.1041 4.37%
calc_interpolate_dists_list 0.0307 0.0125 40.72%

Performance was measured using line_profiler with Python 3.10.16.

Optimization Details

calc_interpolate_dists_list

The main bottleneck in this function was the use of np.append, which accounted for about 70% of the runtime due to repeated memory reallocation. This has been eliminated by restructuring the function to avoid unnecessary array copying.

generate_local_course

  1. Replaced the per-element interpolate loop with a vectorized version interpolate_vectorized, enabling batch computation with NumPy.
  2. Precomputed the length of result arrays to avoid dynamic resizing during the loop.
  3. The function now returns NumPy arrays instead of Python lists to facilitate downstream vectorized processing.

calc_paths

Constructed SE(2) transformation matrices to accelerate coordinate transformations using NumPy matrix operations.

CheckList

  • Did you add an unittest for your new example or defect fix?
  • Did you add documents for your new example?
  • All CIs are green? (You can check it after submitting)

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR optimizes the Reeds-Shepp path planning module by leveraging NumPy’s vectorized computations to significantly reduce runtime in key functions.

  • Replaces iterative loops with vectorized operations in functions calc_interpolate_dists_list, generate_local_course, and a new interpolate_vectorized.
  • Updates coordinate transformations in calc_paths to use NumPy matrix operations for improved performance.
Comments suppressed due to low confidence (2)

PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py:350

  • Consider adding a docstring to calc_interpolate_dists_list to explain its role in precomputing distance arrays and how the endpoint is handled.
def calc_interpolate_dists_list(lengths: List[float], step_size: float) -> List[NDArray[np.floating]]:

PathPlanning/ReedsSheppPath/reeds_shepp_path_planning.py:399

  • Add a docstring for interpolate_vectorized to detail its behavior for different modes ('S', 'L', 'R') and clarify how the vectorized computations are performed.
def interpolate_vectorized(

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.

1 participant