HaxeFlixel / HaxeFlixel/flixel
Optimize matrix recomputation
Nobody has claimed this yet.
- Dominant language
- Haxe
- Stars
- 2.2k
- Forks
- 522
- Avg merge
- 34m
- Merged PRs (30d)
- 1
Description
See my original comments for a more detailed explanation: https://github.com/HaxeFlixel/flixel/issues/2978#issuecomment-3697398003, https://github.com/HaxeFlixel/flixel/issues/2978#issuecomment-3700155732
TL;DR: Matrix recalculations every frame, per sprite, take up a significant chunk of time in the draw() call (~60%), which can get problematic with many sprites displayed
I've played around with it a bit, and with some tricks I've managed to shave down the time taken by around ~90%. It's quite hacky though: https://github.com/ACrazyTown/flixel/commit/fda8f294896fd61c8cf6ce576cc8d09f502efd65. I've managed to do so by querying the screen position only once per draw() (with a helper point) instead of twice in both isOnScreen() and prepareComplexMatrix(), and avoiding various FlxPoint helper methods and getters/setters.
What I haven't played around with is recalculating the matrix on demand, i.e. only doing it when the sprite is moved or rotated
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the draw() path and the referenced isOnScreen() and prepareComplexMatrix() methods, then review the linked original discussion and experimental commit. Compare the current per-frame matrix and screen-position work with the proposed on-demand recalculation; done should address the reported draw-time cost without changing sprite behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- game-dev, performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100