Skip to content

Preserve cached rotations during sprite collision queries - #285

Open
fderop wants to merge 2 commits into
cortex-command-community:developmentfrom
fderop:perf/cache-collision-transforms
Open

fderop wants to merge 2 commits into
cortex-command-community:developmentfrom
fderop:perf/cache-collision-transforms

Conversation

@fderop

@fderop fderop commented Oct 2, 2026 •

Copy link
Copy Markdown

Sprite collision queries copied rotation matrices but discarded their cached coefficients, so later transforms repeated sine and cosine calculations.
The copy now preserves the coefficients and their validity flag:

m_Elements[0][0] = reference.m_Elements[0][0];
m_Elements[0][1] = reference.m_Elements[0][1];
m_Elements[1][0] = reference.m_Elements[1][0];
m_Elements[1][1] = reference.m_Elements[1][1];
m_ElementsUpdated = reference.m_ElementsUpdated;

Valid caches remain valid. Invalid caches still recalculate on use.
MOSprite::HitTestAtPixel also drops its redundant matrix copy. The existing const operator retains a local copy, so queries do not mutate shared matrices.

Three process pairs on an M3 Pro with GCC 15.2 show 10.7–24.6% less collision-query time, depending on cache state.
All 29,491,200 pixel-query results and matrix float-bit hashes match. Concurrent-reader checks and full release builds pass.
These are function timings, not FPS gains.

Only Matrix.cpp and MOSprite.cpp change in production. Fixture and reproduction instructions.

@fderop
fderop marked this pull request as ready for review October 2, 2026 18:28
@Causeless
Causeless enabled auto-merge October 3, 2026 18:54
@Causeless

Copy link
Copy Markdown
Contributor

Not sure we want to include the benchmarks stuff, but I don't see an issue with it for now

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