Skip to content

chore: Add a collision benchmark for Path contour hitboxes - #3

Merged
adario merged 1 commit into
feat/path-shapesfrom
benchmark/path-collision
Sep 13, 2026
Merged

adario merged 1 commit into
feat/path-shapesfrom
benchmark/path-collision

Conversation

@spydon

@spydon spydon commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Adds path_collision_benchmark.dart, a harness benchmark that runs the collision detection system with a hitbox built by PolygonHitbox.contour against circles, rectangles, a hand-written polygon, and itself. Each scene has 50 moving, rotating shapes of the subject kind and 50 of the other kind in an 800 by 800 world, and hitboxes only narrow-phase against the partner kind so a scene measures exactly that pairing. The subject is the flame logo path from path_contour_shapes.dart, 37 vertices at 60 pixels. The baseline is the same logo hand-written from its 10 anchor points, which is what a game on main has to use today. The polygon scenes compile on main as well, so the two branches can be compared by running the file on both.

Results on this branch, milliseconds per 20 ticks in JIT through flutter test:

Scene Path hitbox on this branch Hand-written polygon on this branch Hand-written polygon on main
vs circle 17.5 6.7 6.9
vs rectangle 12.4 6.2 6.4
vs 10-vertex polygon 16.0 10.3 10.7
vs itself 92.0 10.3 10.7

Two conclusions from that: the branch does not slow down existing polygons, and the path hitbox pays for its vertex count quadratically against other polygons. #4 fixes most of that in the narrow phase and brings path vs path down to 11.4, and #5 takes it further to 7.7 by making the global vertex and circle computations allocation free.

Checklist

  • I have followed the Contributor Guide when preparing my PR.
  • [-] I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • [-] I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

Runs the collision detection system with a hitbox sampled from a Path contour against circles, rectangles, hand-written polygons, and itself, next to the same scenes with a hand-written polygon of the same shape. The polygon scenes also compile on main, so the two can be compared by running the file on both branches.
@adario

adario commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Very cool benchmark!
LGTM

@adario
adario merged commit 501d53d into feat/path-shapes Sep 13, 2026
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.

2 participants