Skip to content

Per-step allocation and inner-loop cleanups in the step pipeline - #989

Closed
marknefedov wants to merge 1 commit into
dimforge:masterfrom
marknefedov:per-step-alloc-cleanups
Closed

Per-step allocation and inner-loop cleanups in the step pipeline#989
marknefedov wants to merge 1 commit into
dimforge:masterfrom
marknefedov:per-step-alloc-cleanups

Conversation

@marknefedov

@marknefedov marknefedov commented Aug 14, 2026

Copy link
Copy Markdown

Four changes removing per-step allocator traffic and one loop-invariant lookup:

  • carry_warmstart_data: the manifold-level subshape_pos1() lookup moved out of the per-point matching loop. It is invariant there and always None for cluster manifolds, but was re-checked for every candidate point of an O(prev_points x target_points) loop.
  • Narrow phase: the serial pair-transition buffer is a persistent NarrowPhase scratch field (take and restore), so its capacity survives across steps. Same idiom the function already uses for update_candidates and solver_graph_dirty.
  • Substep: the joint island event drain().collect() replaced with the take-and-restore idiom used three lines below for multibody chain events. Removes a per-substep Vec.
  • Staged island solver: the two generic multibody solver velocity vectors are resized in place and zeroed instead of rebuilt with DVector::zeros every step. Reallocation only happens when the total DoF count grows.

On the benchmark scenes from #988 the effect was within noise (-1.6% on the pyramid at p = 0.05, wider on the terrain scene). Withdrawn for lack of demonstrable numbers.

- carry_warmstart_data: hoist the manifold-level subshape_pos1 lookup
  out of the per-point matching loop (it is invariant there, and always
  None for cluster manifolds).
- Narrow phase: keep the serial pair-transition buffer as a persistent
  NarrowPhase scratch field (mem::take + restore) so its capacity is
  reused across steps instead of reallocating each step.
- Substep: replace the joint island event drain().collect() with the
  take + restore idiom already used for multibody chain events,
  removing a per-substep Vec allocation.
- Staged island solver: resize the generic multibody solver velocity
  vectors in place and zero them instead of allocating two fresh
  DVectors every step.

rapier3d test suite passes.
@marknefedov

Copy link
Copy Markdown
Author

Closing this one: the measured effect on the benchmark scenes was within noise, and I'd rather not ask for review time on changes I can't demonstrate. The benchmarks in #988 stand on their own; if a scene shows these allocations mattering I'll reopen with numbers.

@marknefedov
marknefedov deleted the per-step-alloc-cleanups branch August 14, 2026 21:05
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