From e8f3067e17da3f5e23864b5e8a897cdbd95029ab Mon Sep 17 00:00:00 2001 From: Dmitry Stepanov Date: Sun, 12 Jul 2026 22:42:46 +0300 Subject: [PATCH] improved animation system performance - removed most of redundant memory allocations that happened each frame - overall gain is about 10% --- fyrox-animation/src/pose.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/fyrox-animation/src/pose.rs b/fyrox-animation/src/pose.rs index 8b6bbf3d7..45a0178e4 100644 --- a/fyrox-animation/src/pose.rs +++ b/fyrox-animation/src/pose.rs @@ -39,7 +39,11 @@ impl NodePose { /// Performs a blending of the current with some other pose. See [`super::value::TrackValue::blend_with`] docs for more /// info. pub fn blend_with(&mut self, other: &NodePose, weight: f32) { - self.values.blend_with(&other.values, weight) + if self.values.values.is_empty() { + other.values.values.clone_into(&mut self.values.values) + } else { + self.values.blend_with(&other.values, weight) + } } } @@ -55,7 +59,16 @@ impl AnimationPose { pub fn clone_into(&self, dest: &mut AnimationPose) { dest.reset(); for (handle, local_pose) in self.poses.iter() { - dest.poses.insert(*handle, local_pose.clone()); + match dest.poses.entry(*handle) { + Entry::Occupied(mut entry) => { + let values = &mut entry.get_mut().values.values; + values.clear(); + values.extend_from_slice(&local_pose.values.values); + } + Entry::Vacant(entry) => { + entry.insert(local_pose.clone()); + } + } } dest.root_motion.clone_from(&self.root_motion); } @@ -107,9 +120,12 @@ impl AnimationPose { } } - /// Clears the pose. + /// Clears the pose by dropping the calculated values for each node pose. Does **NOT** clear the + /// poses container itself. pub fn reset(&mut self) { - self.poses.clear(); + for pose in self.poses.values_mut() { + pose.values.values.clear(); + } } /// Returns a reference to inner node pose map.