Skip to content

perf: Compose one transform for polygon global vertices and hoist the circle center out of the edge loop - #5

Merged
adario merged 1 commit into
perf/narrow-phase-overlap-pathfrom
perf/polygon-transform-and-circle-hoist-path
Sep 13, 2026
Merged

adario merged 1 commit into
perf/narrow-phase-overlap-pathfrom
perf/polygon-transform-and-circle-hoist-path

Conversation

@spydon

@spydon spydon commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Description

The same changes as flame-engine#4046, cherry-picked onto #4 so the path contour hitboxes get them right away. Stacked on #4 because the circle change touches the intersection code that PR changed.

Compose one transform for the global vertices. PolygonComponent.globalVertices walked the ancestors once per vertex with an allocation per level, and validated its cache with three more ancestor walks. It now composes a single 2D affine transform, writes the vertices into the preallocated list, and keys the cache on the transform values and size. For the 37-vertex flame contour under a rotating parent one call went from 1.24 to 0.19 microseconds.

Hoist the circle center and radius out of the edge loop. Circle-versus-polygon computed absoluteCenter and scaledRadius per polygon edge. They are now computed once per pair, and edges whose bounding box is farther than the radius from the center are skipped.

Measured with the benchmark from #3 on this branch, milliseconds per 20 ticks in JIT, 50 hitboxes of each kind, starting from #4:

Scene #4 Global vertices Plus circle hoist
path vs circle 10.2 8.7 4.7
path vs rectangle 6.8 4.2 4.0
path vs polygon 5.9 3.5 3.4
path vs path 11.4 7.8 7.7
polygon vs circle 5.4 4.7 3.4
polygon vs rectangle 5.1 3.0 2.9
polygon vs polygon 5.9 3.4 3.3

For reference, path vs path was 92.0 before #4.

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.

… circle center out of the edge loop

PolygonComponent.globalVertices walked the ancestor chain once per vertex with an allocation per level and validated its cache with three more ancestor walks. It now composes a single 2D affine transform, writes the vertices into the preallocated list, and keys the cache on the transform values and the size. CirclePolygonIntersections computed the absolute center and scaled radius of the circle for every polygon edge; they are now computed once per pair, and edges whose bounding box is farther than the radius from the center are skipped.
@adario

adario commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Looks great!
LGTM

@adario
adario merged commit 7c57740 into perf/narrow-phase-overlap-path 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