Skip to content

perf(mobile): reduce RRT collision work and assemble sparse pose graphs - #817

Merged
petercorke merged 3 commits into
petercorke:mainfrom
kVinsom:perf/755-mobile-planning
Oct 22, 2026
Merged

petercorke merged 3 commits into
petercorke:mainfrom
kVinsom:perf/755-mobile-planning

Conversation

@kVinsom

@kVinsom kVinsom commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

RRT planning checked every candidate path for collisions before rejecting connections longer than its existing length limit. Reject these connections first, avoiding unnecessary vehicle polygon transforms and intersection tests.

PoseGraph allocated a dense (3N, 3N) normal matrix and scanned it to create CSR. Accumulate only the contributing 3x3 blocks, then construct the sparse matrix directly. Preserve the original addition order and remove explicit zeros so the solver sees the same coefficients and sparsity structure.

Adds eight regression cases and examples/benchmark_mobile.py, which records timings and dependency versions and can save the final tree, path and poses for comparison. Tests cover the dense reference equations, repeated/reversed constraints, angle wrapping, a single isolated pose, avoiding dense allocation, and RRT's length boundary.

Related issue

Addresses the unnecessary RRT collision work and dense PoseGraph assembly in #755. Per-factor transform batching and optional k-d trees remain outside this PR; this does not close the broader investigation.

Performance

Local medians of three runs, excluding loading/construction, on Windows with Python 3.12.14, NumPy 2.5.4, SciPy 1.18.1, SpatialMath 1.1.18 and pgraph 1.0.0. Baseline: a4b27adf. RRT uses seed 0 with plotting disabled; PoseGraph uses up to five iterations.

Case Before After Speedup
RRT, 100 added vertices 1.032 s 0.410 s 2.52x
RRT, 400 added vertices 10.145 s 4.398 s 2.31x
killian-small.toro, 1,941 poses 1.947 s 1.180 s 1.65x
killian.g2o.zip, 3,873 poses 2.508 s 0.910 s 2.76x

The saved RRT trees, query paths and optimised poses match exactly between revisions for both sizes in this environment. Timings are illustrative and machine-dependent.

Run on each revision with the same dependencies:

python examples/benchmark_mobile.py --output result.npz
python examples/benchmark_mobile.py --npoints 400 --graph data/killian.g2o.zip --output large-result.npz

Validation

  • Review follow-up: added the RVC3 Appendix F.2.4.1 reference beside the H/b block accumulation. This is a comment-only change; numerical results and public behaviour are unchanged. Re-ran 41 focused performance/PoseGraph tests (plus 5 subtests), all passed.
  • Focused planner/PoseGraph suite: 159 passed, plus 18 subtests, on Windows/Python 3.12 and Linux/Python 3.14.
  • Full Windows suite during implementation: 1434 passed, 39 failed, 166 skipped, plus 91 passing subtests. All 39 failures also occur on the unchanged base, which had 1427 passing tests. The subsequent isolated-pose regression also passes on both platforms. Existing failures include unavailable compiled functionality and model-cache permissions; the full local suite is not green.
  • On the unchanged base, the two RRT optimisation regressions and the dense-allocation regression fail as intended; dense-reference comparisons pass.
  • mypy: no issues in 163 source files. Ruff passes for the new files, adds no findings in modified modules, and formatting passes for all four files. git diff --check passes.

Checklist

  • PR title follows Conventional Commits
  • Tests pass locally (pytest) — focused suite passes; full-suite baseline failures described above
  • Added/updated tests for this change
  • New/changed code uses modern type hints
  • Docstrings updated in reST style
  • PR is focused on mobile planning performance
  • No personal-project test data or notebooks included

Implementation, tests and documentation were developed with OpenAI Codex assistance.

Reject overlong RRT connections before collision checks. Assemble pose-graph normal equations from sparse blocks while preserving accumulation order. Add regression tests and a reproducible benchmark for petercorke#755.
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 6 high

Alerts:
⚠ 6 issues (≤ 0 issues of at least minor severity)

Results:
6 new issues

Category Results
Security 6 high

View in Codacy

🟢 Metrics 23 complexity · 0 duplication

Metric Results
Complexity 23
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (126c410) to head (b0d40ec).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/roboticstoolbox/mobile/PoseGraph.py 0.00% 11 Missing ⚠️
src/roboticstoolbox/mobile/RRTPlanner.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #817   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files        146     146           
  Lines      17164   17168    +4     
=====================================
- Misses     17164   17168    +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petercorke

Copy link
Copy Markdown
Owner

Thank you for the performance work on the RRT and the pose graph. I compared the optimised poses for pg1.g2o and killian-small.toro, and the "Total cost" at each iteration, with the output printed in Robotics, Vision & Control (chapter 6), and they match exactly, with the sparse version about 1.5× faster.

One small request: the book's Appendix F.2.4.1 describes the edge loop with the H and b blocks accumulated and recommends sparse storage, which is what your code does. Could you add a short comment pointing there, so a reader can map the dictionary-of-blocks code to the book's H_ij += … step? Then I'll update the branch and merge it.

Co-Authored-By: Codex (GPT-6) <noreply@openai.com>
@kVinsom

kVinsom commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Thank you, Peter, for checking the results against the book. I have added a short comment beside the block accumulation pointing to RVC3, Appendix F.2.4.1, and its H_ij and b_i accumulation steps. This only changes the comment; all 41 focused performance/PoseGraph tests (plus 5 subtests) pass.

I also sent you an email from kachmarykmi@gmail.com to peter.corke@qut.edu.au. If you have time, I would be very grateful for a reply whenever convenient. Thank you again for your time and guidance!

@petercorke
petercorke enabled auto-merge (squash) October 22, 2026 01:01
@petercorke
petercorke merged commit ff0e902 into petercorke:main Oct 22, 2026
22 of 23 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 22, 2026
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.

2 participants