Cache the last-accessed segment in Path::getPathSegment - #3800
Cache the last-accessed segment in Path::getPathSegment#3800hugogo1998 wants to merge 3 commits into
Conversation
Path::getPathSegment scans path_segments_ from the front on every call. The TOTG integration loop calls it (directly and via getTangent/getConfig/getCurvature) thousands of times per trajectory at monotonically-advancing arc-length positions, so the from-front rescan makes the whole time-parameterization pass O(steps * segments) instead of the O(steps) it could be. Cache the last-found segment and resume the scan from there when the new query position is at or after that segment's start, which is the common case since queries only move forward during integration; fall back to scanning from the front otherwise. Finds the same segment and applies the same position adjustment as before, so output is unchanged. Copy-constructed Paths start with the cache marked invalid, since cache_valid_ isn't in the copy constructor's init list and its default member initializer applies.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan includes up to 3 reviews per rolling hour; 2 remain after this review. 📝 WalkthroughWalkthrough
ChangesPath-segment cache
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This change only optimizes repeated path-segment lookups while preserving segment selection behavior; targeted tests pass, and no actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Description
Path::getPathSegment()currently scans from the beginning for every lookup. During time parameterization, queries usually move forward, so the same segments are visited repeatedly.This change stores the last segment index and resumes forward queries from there. Backward queries restart at the beginning. The cached index is atomic so concurrent const queries remain safe.
Results
Mean time for a full time-parameterization pass:
Testing
Added coverage for forward and backward queries, segment boundaries, copied paths, and concurrent queries.
Built
moveit_coreand ran the targeted test inmoveit/moveit2:humble-ci: 18/18 gtests passed; colcon reported 19 tests, 0 errors, 0 failures, 0 skipped.Checklist