Build the unpadded collision env lazily in allocateCollisionDetector - #3801
Open
agentperfopt wants to merge 1 commit into
Open
Build the unpadded collision env lazily in allocateCollisionDetector#3801agentperfopt wants to merge 1 commit into
agentperfopt wants to merge 1 commit into
Conversation
allocateCollisionDetector runs on every diff()/clearDiffs(), which is frequent during planning, and builds two full collision environments every time: cenv_ (padded) and cenv_unpadded_. The unpadded one is only read by unpadded self-collision/distance checks (checkSelfCollision unpadded, distanceRobot), which most planning never calls, so on the common path it's built and never touched. Defer building cenv_unpadded_ to first use instead of building it eagerly in allocateCollisionDetector. getCollisionEnvUnpadded() now builds it on first call and caches the result, copy-constructing from the parent's unpadded env for child scenes (same as before, just later) or from the world/model directly for root scenes. Once built it's cached exactly like before; scenes that never query it just never pay for it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Builds on #464 (correctness fix: child scenes must copy-construct the parent's collision environments so attached objects carry over, instead of building fresh from the robot model). That fix builds two full collision environments on every
diff()/clearDiffs()call — the paddedcenv_and the unpaddedcenv_unpadded_— butcenv_unpadded_is only read by unpadded self-collision and distance checks (checkSelfCollisionunpadded,distanceRobot), which most planning never calls. On the common padded-only path, it's built and never touched.This defers building
cenv_unpadded_to first use:getCollisionEnvUnpadded()builds it on first call and caches the result exactly as before (copy-constructed from the parent's unpadded env for child scenes, or from world+model for root scenes). Scenes that never query it never pay to build it.Results
Real FCL 0.7,
allocateCollisionDetectortimed directly, us/call:Worth stating plainly since it changes who this helps: this is a conditional win, not a universal one. It depends on how often planning actually queries the unpadded env:
Padded-only planning is the common case (most self-collision/distance checking uses padding), so most workloads land near the top of that table. A planner that queries the unpadded env on every scene gets no win and no loss — the deferral just moves the same build to a different point in the call, it doesn't add one.
Correctness
When the unpadded env is queried, it's built the identical way it always was (copy-constructed from the same parent source, once, then cached) — just later. One thing I want to flag rather than quietly work around:
getCollisionEnvUnpadded()records the parent's currentcenv_unpadded_const_pointer at scene-creation time, not a live reference to the parent's detector. If a parent scene's own unpadded env is itself still deferred (never queried) at the moment a child scene is created off of it, that pointer is null, and the child would build its unpadded env fresh from world+model instead of cascading up to the parent — the same kind of gap #464 fixed, just for a specific nested-diff ordering. I didn't fix this here: I don't have a moveit2 build in this environment to verify whether it's reachable in practice (attached-object handling in the FCL collision env is deeper than I could confirm from reading alone), and I'd rather flag it precisely than either silently ship it or silently redesign around an unconfirmed concern. Worth a maintainer's eyes given how attached objects factor into unpadded self-collision checks specifically.Checklist
Found by an automated tool that profiles merged PRs for headroom the PR itself didn't cover; the correctness note above is mine, from reading the change against the current code, not something the tool flagged.