Reduce allocations in Matrix4Tween.lerp to improve transform animation performance - #190659
Draft
FelixMittermeier wants to merge 1 commit into
Draft
Reduce allocations in Matrix4Tween.lerp to improve transform animation performance#190659FelixMittermeier wants to merge 1 commit into
FelixMittermeier wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #32055
Matrix4Tween.lerpcurrently allocates decomposition outputs plus temporary translation, rotation, and scale objects on every animation tick. A single interpolation creates at least 16 avoidable vector and quaternion wrappers, along with their typed-data storage, before composing the required result matrix. This adds allocation and garbage-collection pressure to transform animations.The solution is to retain six lazily initialized scratch objects per tween, decompose the current endpoints into them on every call, and perform the existing scale, add, and normalize operations in place. The arithmetic order and normalized quaternion interpolation remain unchanged, mutable endpoints are still observed on every evaluation, and each call continues to return an independent
Matrix4.Performance
Measured with the maintained
matrix4_tween_bench.dartbenchmark using Dart 3.14 on macOS arm64. Each reported runtime covers 2,050 lerps and is the median of five runs.Pre-launch Checklist
///).