Skip to content

Collide as the reference keeps it: encoded body sims on the contact, dense fat boxes (#121) - #140

Merged
nicolas-maman merged 2 commits into
mainfrom
perf/collide-encoded
Oct 9, 2026
Merged

nicolas-maman merged 2 commits into
mainfrom
perf/collide-encoded

Conversation

@nicolas-maman

Copy link
Copy Markdown
Collaborator

Ports two pieces of Box3D e77352c's collide pass that were missing (#121):

  • Encoded body sims on the contact (encodedBodySimA/B): the awake index for an awake body, -(index + 2) for a static one, NULL_INDEX otherwise. They are kept current wherever a sim moves, as the reference does: contact creation, entering the graph, wake, sleep, and the sim swapped into a destroyed or transferred body's place (refresh_body_contact_indices, the reference's b3RefreshBodyContactIndices). The collide pass and both contact prepares read them instead of going shape, body, set, sim and rewriting the indices every step. A sleeping body's sim is found through the body (resolve_contact_body_sim, the reference's b3ResolveContactBodySim).
  • Dense fat boxes (World.fat_aabbs by shape id, the reference's fatAABBs): the overlap test reads two entries of a dense array, and a recycled contact never touches its shapes.

Nothing is computed differently: the golden determinism trace (1136 steps) and every benchmark checksum are unchanged.

Edge cases: validate_solver_sets now checks every contact's encodings against its bodies (as b3ValidateSolverSets does), so every existing test that validates covers them. A new test_encoded_sims in tests/test_edge_cases.ae drives each path that moves a sim, validating after every step: islands sleeping and waking one at a time, a non-touching contact between an awake body and a sleeping one, a static and an awake sim swapped into a destroyed body's place, kinematic and back, disabled and enabled. Leaving out the refresh on a destroy fails 4 of its checks, and leaving out the wake fixup fails 8.

Pinned to one core, 5 runs each rotated, ms per step (median):

scene main this PR Box3D e77352c, AVX2
large pyramid 6.81 6.47 5.39
collide 1.00-1.08 0.81-0.85 0.81-0.94
many pyramids 14.86 14.34 12.40
collide 2.49-2.97 1.81-1.97 1.97-2.36
joint grid 10.75 10.85 10.27
mixed pile, awake 2.58-2.64 2.52-2.55 1.99-2.02

Collide is level with the reference on the large pyramid and ahead on the many pyramids. The scenes stand at 1.2x, 1.15x and 1.05x; the mixed pile at 1.26x, its collide still behind because more of its contacts compute manifolds afresh in double. The rest of #121 is the lanes (aether#2550), the prepare, and the pairs' double tree.

Local gate on Aether 0.794.0: every suite passes and the golden trace matches bit for bit. Pins: Aether 0.794.0 and aeb v0.325, the latest releases.

Refs #121.

@nicolas-maman
nicolas-maman merged commit 0c8a2de into main Oct 9, 2026
2 checks passed
@nicolas-maman
nicolas-maman deleted the perf/collide-encoded branch October 9, 2026 01:13
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