Skip to content

Conversation

@capdevon
Copy link
Contributor

This PR introduces a minor but impactful performance optimization within the MotionEvent class.

Previously, the computeTargetDirection() method repeatedly created new Quaternion objects (q and q2) on each call when handling Path and PathAndRotation direction types. This constant object allocation can lead to unnecessary garbage collection overhead, particularly in performance-critical game loops or animations.

To address this, I've refactored the method to utilize a single, reusable Quaternion class member variable (tempRotation). By reusing this existing object, we significantly reduce memory allocations and subsequent garbage collection cycles, resulting in a modest but noticeable performance improvement, especially when many MotionEvents are active or when the method is called frequently.

@yaRnMcDonuts yaRnMcDonuts added this to the v3.9.0 milestone May 22, 2025
@yaRnMcDonuts yaRnMcDonuts merged commit 6b143d7 into jMonkeyEngine:master Jun 15, 2025
16 checks passed
@capdevon capdevon deleted the capdevon-MotionEvent branch June 30, 2025 10:10
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.

3 participants