Skip to content

218 composable dispatcher #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

Vrixyz
Copy link
Owner

@Vrixyz Vrixyz commented Feb 24, 2025

as of 4a33cb3 ; this uses TypeId to be explicit about how each specific types are handled, here are the current handled interactions:

Testing

This implementation allows us to test which combination of shapes are supported (and eventually the path taken).

Details

(RoundShape::<Cuboid> HalfSpace),
(Ball RoundShape::<Capsule>),
(RoundShape::<Triangle> RoundShape::<HalfSpace>),
(RoundShape::<TriMesh> Polyline),
(TriMesh Compound),
(Compound TriMesh),
(Ball Segment),
(HalfSpace Cuboid),
(ConvexPolygon HalfSpace),
(RoundShape::<Compound> Polyline),
(Polyline Ball),
(Compound RoundShape::<Triangle>),
(Compound Capsule),
(RoundShape::<HeightField> Polyline),
(TriMesh ConvexPolygon),
(Compound RoundShape::<Compound>),
(HeightField Polyline),
(TriMesh RoundShape::<Triangle>),
(TriMesh HalfSpace),
(RoundShape::<Capsule> Compound),
(RoundShape::<Ball> Compound),
(Compound RoundShape::<Polyline>),
(ConvexPolygon RoundShape::<Ball>),
(TriMesh RoundShape::<Compound>),
(RoundShape::<HeightField> Ball),
(Cuboid Ball),
(RoundShape::<Ball> HalfSpace),
(RoundShape::<ConvexPolygon> Compound),
(RoundShape::<Triangle> HalfSpace),
(HalfSpace ConvexPolygon),
(Polyline Triangle),
(HalfSpace RoundShape::<Segment>),
(Capsule RoundShape::<HalfSpace>),
(Ball Polyline),
(RoundShape::<Capsule> HalfSpace),
(HeightField Ball),
(RoundShape::<ConvexPolygon> RoundShape::<Ball>),
(RoundShape::<Segment> Compound),
(Triangle TriMesh),
(RoundShape::<ConvexPolygon> Ball),
(Capsule TriMesh),
(HalfSpace RoundShape::<Ball>),
(RoundShape::<Capsule> RoundShape::<HalfSpace>),
(RoundShape::<HalfSpace> ConvexPolygon),
(RoundShape::<Ball> RoundShape::<HeightField>),
(RoundShape::<Cuboid> RoundShape::<Ball>),
(RoundShape::<Triangle> RoundShape::<Ball>),
(HalfSpace RoundShape::<Triangle>),
(Compound RoundShape::<HeightField>),
(RoundShape::<Capsule> RoundShape::<Ball>),
(Polyline ConvexPolygon),
(Segment Polyline),
(Segment HalfSpace),
(Compound HeightField),
(Segment Compound),
(RoundShape::<Compound> Compound),
(HalfSpace RoundShape::<Cuboid>),
(Compound Compound),
(Cuboid Cuboid),
(Cuboid Compound),
(Polyline Polyline),
(Polyline HeightField),
(TriMesh TriMesh),
(Polyline RoundShape::<Polyline>),
(Compound Ball),
(RoundShape::<Ball> RoundShape::<Triangle>),
(Triangle Compound),
(Cuboid Segment),
(Segment RoundShape::<HalfSpace>),
(TriMesh Ball),
(TriMesh RoundShape::<Cuboid>),
(Polyline RoundShape::<Compound>),
(Polyline Compound),
(TriMesh RoundShape::<Ball>),
(RoundShape::<ConvexPolygon> Polyline),
(Ball Ball),
(Polyline Capsule),
(RoundShape::<Ball> RoundShape::<Cuboid>),
(Compound RoundShape::<Capsule>),
(RoundShape::<HalfSpace> Ball),
(Segment RoundShape::<Ball>),
(RoundShape::<TriMesh> Compound),
(RoundShape::<Ball> TriMesh),
(RoundShape::<HalfSpace> Compound),
(Compound Polyline),
(Compound RoundShape::<TriMesh>),
(RoundShape::<TriMesh> Ball),
(RoundShape::<Ball> RoundShape::<HalfSpace>),
(HalfSpace RoundShape::<Capsule>),
(Polyline RoundShape::<Capsule>),
(TriMesh RoundShape::<TriMesh>),
(HeightField TriMesh),
(HalfSpace Polyline),
(Capsule Ball),
(Segment Cuboid),
(ConvexPolygon TriMesh),
(RoundShape::<Segment> Polyline),
(Polyline RoundShape::<HeightField>),
(RoundShape::<HeightField> Compound),
(Ball RoundShape::<Triangle>),
(RoundShape::<Cuboid> Ball),
(RoundShape::<Segment> TriMesh),
(RoundShape::<Segment> RoundShape::<Ball>),
(RoundShape::<HalfSpace> RoundShape::<Segment>),
(RoundShape::<Ball> Capsule),
(Capsule RoundShape::<Ball>),
(RoundShape::<HeightField> TriMesh),
(RoundShape::<HalfSpace> RoundShape::<Capsule>),
(Triangle HalfSpace),
(RoundShape::<Polyline> RoundShape::<Ball>),
(Ball RoundShape::<ConvexPolygon>),
(RoundShape::<Triangle> Polyline),
(RoundShape::<Ball> Triangle),
(Ball RoundShape::<HeightField>),
(Cuboid Polyline),
(Cuboid TriMesh),
(Compound RoundShape::<Ball>),
(RoundShape::<Capsule> Ball),
(RoundShape::<Triangle> Ball),
(RoundShape::<HalfSpace> Cuboid),
(RoundShape::<HalfSpace> RoundShape::<Triangle>),
(Polyline HalfSpace),
(Ball RoundShape::<TriMesh>),
(TriMesh Triangle),
(Cuboid RoundShape::<Ball>),
(Polyline RoundShape::<Cuboid>),
(RoundShape::<Polyline> Polyline),
(RoundShape::<Ball> ConvexPolygon),
(Compound Triangle),
(Segment TriMesh),
(ConvexPolygon RoundShape::<HalfSpace>),
(Compound RoundShape::<HalfSpace>),
(Compound Cuboid),
(RoundShape::<Capsule> TriMesh),
(HalfSpace Segment),
(ConvexPolygon Ball),
(Capsule HalfSpace),
(Ball Triangle),
(Capsule Compound),
(RoundShape::<Cuboid> Compound),
(Polyline RoundShape::<Triangle>),
(RoundShape::<HeightField> RoundShape::<Ball>),
(TriMesh RoundShape::<HeightField>),
(Ball HalfSpace),
(TriMesh Capsule),
(Compound ConvexPolygon),
(Compound Segment),
(RoundShape::<Triangle> Compound),
(Compound HalfSpace),
(RoundShape::<Capsule> Polyline),
(RoundShape::<Ball> RoundShape::<Capsule>),
(Cuboid RoundShape::<HalfSpace>),
(Triangle RoundShape::<Ball>),
(Ball ConvexPolygon),
(RoundShape::<Polyline> Compound),
(Polyline RoundShape::<Ball>),
(TriMesh RoundShape::<Segment>),
(HalfSpace RoundShape::<ConvexPolygon>),
(Polyline Segment),
(RoundShape::<HalfSpace> Triangle),
(RoundShape::<HalfSpace> Segment),
(RoundShape::<Ball> HeightField),
(Polyline RoundShape::<HalfSpace>),
(HalfSpace TriMesh),
(RoundShape::<Cuboid> Polyline),
(Polyline TriMesh),
(HalfSpace Triangle),
(TriMesh RoundShape::<HalfSpace>),
(HeightField Compound),
(Compound RoundShape::<Cuboid>),
(Segment Ball),
(TriMesh HeightField),
(Ball RoundShape::<Segment>),
(Ball Compound),
(Polyline RoundShape::<Segment>),
(RoundShape::<Polyline> TriMesh),
(TriMesh Cuboid),
(RoundShape::<Ball> Cuboid),
(Ball Capsule),
(RoundShape::<Compound> TriMesh),
(Cuboid HalfSpace),
(Triangle RoundShape::<HalfSpace>),
(TriMesh RoundShape::<ConvexPolygon>),
(RoundShape::<Ball> Polyline),
(RoundShape::<HalfSpace> TriMesh),
(Ball RoundShape::<Cuboid>),
(RoundShape::<Cuboid> TriMesh),
(Compound RoundShape::<ConvexPolygon>),
(RoundShape::<TriMesh> RoundShape::<Ball>),
(RoundShape::<HalfSpace> RoundShape::<ConvexPolygon>),
(RoundShape::<HalfSpace> RoundShape::<Ball>),
(RoundShape::<HalfSpace> Capsule),
(RoundShape::<HalfSpace> RoundShape::<Cuboid>),
(Triangle Ball),
(RoundShape::<Triangle> TriMesh),
(RoundShape::<Ball> RoundShape::<Segment>),
(RoundShape::<TriMesh> TriMesh),
(Polyline RoundShape::<TriMesh>),
(Cuboid Triangle),
(TriMesh Segment),
(Polyline RoundShape::<ConvexPolygon>),
(Polyline Cuboid),
(RoundShape::<Ball> RoundShape::<ConvexPolygon>),
(RoundShape::<Ball> Segment),
(RoundShape::<Ball> RoundShape::<Polyline>),
(HalfSpace Compound),
(RoundShape::<Segment> Ball),
(TriMesh RoundShape::<Capsule>),
(RoundShape::<HalfSpace> Polyline),
(RoundShape::<ConvexPolygon> TriMesh),
(RoundShape::<ConvexPolygon> HalfSpace),
(HeightField RoundShape::<Ball>),
(Ball RoundShape::<HalfSpace>),
(TriMesh Polyline),
(RoundShape::<Cuboid> RoundShape::<HalfSpace>),
(RoundShape::<Ball> RoundShape::<TriMesh>),
(Capsule Polyline),
(Triangle Polyline),
(RoundShape::<Polyline> Ball),
(Triangle Cuboid),
(ConvexPolygon Polyline),
(Ball TriMesh),
(Ball HeightField),
(TriMesh RoundShape::<Polyline>),
(RoundShape::<ConvexPolygon> RoundShape::<HalfSpace>),
(RoundShape::<Segment> HalfSpace),
(Compound RoundShape::<Segment>),
(RoundShape::<Segment> RoundShape::<HalfSpace>),
(ConvexPolygon Compound),
(Ball Cuboid),
(HalfSpace Capsule),
(HalfSpace Ball),
(Ball RoundShape::<Polyline>),

Benchmarking

Unfortunately, this implementation comes at a performance price:

test common::dispatcher::bench_intersection_ball_ball                                      ... bench:           5.07 ns/iter (+/- 0.01)
test common::dispatcher::bench_intersection_ball_ball_composable                           ... bench:          19.29 ns/iter (+/- 0.08)
test common::dispatcher::bench_intersection_convex_polyhedron_convex_polyhedron            ... bench:         443.25 ns/iter (+/- 3.44)
test common::dispatcher::bench_intersection_convex_polyhedron_convex_polyhedron_composable ... bench:         447.51 ns/iter (+/- 3.68)

❓ We may want to explore a mixed approach, where known shapes are "hardcoded" in matches to keep the performance, then the function dispatch is considered before reaching out for generic implementations.

To be noted the dispatcher creation is also costly compared to the "no-op" of DefaultQueryDispatcher. But the price should be paid only once at creation so it's not a hot path:

test common::dispatcher::bench_dispatcher_creation                                         ... bench:      11,049.36 ns/iter (+/- 177.26)

Conclusion

@Vrixyz Vrixyz force-pushed the 218_composable_dispatcher branch from 5a66079 to d47a532 Compare March 6, 2025 09:35
@Vrixyz Vrixyz force-pushed the 218_composable_dispatcher branch from 4a33cb3 to c17f765 Compare March 10, 2025 20:11
TODO: fix support map support map in all cases
@@ -0,0 +1,267 @@
use core::any::TypeId;
use std::collections::HashMap;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try with parry hashmap

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