Skip to content

perf(rbd): dedupe shared TriMesh uploads in from_rapier#19

Open
haixuanTao wants to merge 1 commit into
dimforge:mainfrom
haixuanTao:perf/trimesh-dedupe
Open

perf(rbd): dedupe shared TriMesh uploads in from_rapier#19
haixuanTao wants to merge 1 commit into
dimforge:mainfrom
haixuanTao:perf/trimesh-dedupe

Conversation

@haixuanTao

Copy link
Copy Markdown
Contributor

What

RbdState::from_rapier now caches the GPU Shape descriptor of each TriMesh by its parry shape data pointer. When the same SharedShape Arc is cloned across environments — the normal way to build batched scenes with shared terrain — the flat BVH + pseudo-normals are serialized into shape_buffers once and every clone reuses the descriptor (which only holds ranges into the shared buffers).

Why

Batched RL training scenes routinely attach one large terrain trimesh to hundreds or thousands of environments. Before this, from_rapier re-uploaded the mesh per env: with 3 terrain strips of a few thousand triangles across 4096 envs we measured hundreds of MB of duplicated vertex/index/BVH data; after, it's O(unique meshes) — three uploads total.

Scope / safety

  • Cache hit requires the same parry data pointer, i.e. an actual SharedShape clone. Structurally-equal-but-distinct meshes are (correctly) not deduped.
  • TriMesh only — every other shape takes the exact previous path, and scenes without shared trimeshes produce byte-identical buffers.
  • Host-only; no shader change.

cargo check clean on nexus_rbd3d and nexus_rbd2d. Running in production on our terrain-curriculum training (4096 envs × 3 shared strips) for two days.

🤖 Generated with Claude Code

https://claude.ai/code/session_01U2n9RqmxTJb8UG5d1Sjw4W

Batched RL environments typically clone one terrain SharedShape across N
envs; from_rapier re-serialized the flat BVH + pseudo-normals N times. The
GPU Shape descriptor only holds ranges into the shared shape_buffers, so
caching it by the parry shape data pointer uploads each unique trimesh
once — vertex/index memory O(unique meshes) instead of O(envs). TriMesh
only; scenes without shared trimeshes produce byte-identical buffers.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U2n9RqmxTJb8UG5d1Sjw4W
@haixuanTao
haixuanTao force-pushed the perf/trimesh-dedupe branch from ccedf66 to e137707 Compare July 16, 2026 16:03
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