Skip to content

Commit d7b6e5b

Browse files
rjoomenclaude
andcommitted
Reuse ShapeSupportData in CastHullShape to avoid per-call allocation
CastHullShape::computeShapeSupport called getSupport(shape, dir, hint) which created a fresh ShapeSupportData every call, forcing getShapeSupportLog to reallocate its visited vector on every support query. Store two persistent ShapeSupportData members (one per pose) and pass them to the new getSupport overload. The visited vector is now allocated once and reused via std::fill on subsequent calls. Measured: getShapeSupportLog self-time dropped from 2.65% to 2.04%. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2e75a35 commit d7b6e5b

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

tesseract/collision/coal/include/tesseract/collision/coal/coal_casthullshape.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,17 @@ class CastHullShape : public coal::ShapeBase
106106
coal::Transform3s castTransform_;
107107
coal::Transform3s castTransformInv_;
108108

109-
/// Separate support function vertex hints for pose 0 and pose 1.
109+
/// Separate support function vertex hints and data for pose 0 and pose 1.
110110
/// Each getSupport call uses hill-climbing from the hint, so sharing a single
111111
/// hint between the two poses (which query different directions) would cause
112-
/// each to corrupt the other's warm-start.
112+
/// each to corrupt the other's warm-start. The ShapeSupportData holds the
113+
/// visited-vertex buffer reused across calls to avoid per-call allocation.
113114
/// @note Not thread-safe: each thread must use its own CastHullShape instance.
114115
/// The collision managers ensure this via per-thread clone().
115116
mutable int hint0_{ 0 };
116117
mutable int hint1_{ 0 };
118+
mutable coal::details::ShapeSupportData support_data0_;
119+
mutable coal::details::ShapeSupportData support_data1_;
117120
};
118121

119122
} // namespace tesseract::collision::tesseract_collision_coal

tesseract/collision/coal/src/coal_casthullshape.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,17 +143,20 @@ void CastHullShape::computeShapeSupport(const coal::Vec3s& dir,
143143
// Use WithSweptSphere so that shapes with intrinsic radii (Sphere, Capsule)
144144
// include that radius in the support point — necessary for correct swept-hull
145145
// geometry and matching the behavior of the former castHullGetSupportFunc.
146-
// Each pose gets its own vertex hint so the two hill-climbing searches
147-
// warm-start independently.
146+
// Each pose gets its own vertex hint and ShapeSupportData so the two
147+
// hill-climbing searches warm-start independently and reuse their visited
148+
// buffers across calls.
148149
const coal::Vec3s s0 =
149-
coal::details::getSupport<coal::details::SupportOptions::WithSweptSphere>(shape_.get(), dir, hint0_);
150+
coal::details::getSupport<coal::details::SupportOptions::WithSweptSphere>(
151+
shape_.get(), dir, hint0_, support_data0_);
150152

151153
// Support at pose 1 (shape at castTransform_).
152154
// Rotate the query direction into the local frame of pose 1, compute support,
153155
// then transform the result back to the local frame of pose 0.
154156
const coal::Vec3s dir_local1 = castTransformInv_.getRotation() * dir;
155157
const coal::Vec3s s1_local =
156-
coal::details::getSupport<coal::details::SupportOptions::WithSweptSphere>(shape_.get(), dir_local1, hint1_);
158+
coal::details::getSupport<coal::details::SupportOptions::WithSweptSphere>(
159+
shape_.get(), dir_local1, hint1_, support_data1_);
157160
const coal::Vec3s s1 = castTransform_.transform(s1_local);
158161

159162
// Return the support of the convex hull of both poses (Schulman et al. 2013).

0 commit comments

Comments
 (0)