perf: improved garbage created by tweens slightly

They still do generate a lot of garbage but with boxed value pools I made the boxes reusable, it still does generate garbage through the delegate creation, gotta find a solution for them later
This commit is contained in:
2025-08-14 20:31:46 +03:00
parent 746d29fb7a
commit f5a7077570
15 changed files with 278 additions and 57 deletions

View File

@@ -4,6 +4,21 @@ namespace Engine.Systems.Tween;
public static class TweenVector3DExtensions
{
private static readonly BoxedPool<Vector3D> boxedVector3DPool = new(2);
public static ITween TweenVector3D(this Vector3D initialVector3D, ITweenManager tweenManager, float duration, Vector3D targetVector3D, System.Action<Vector3D> setMethod)
=> tweenManager.StartTween(duration, t => setMethod?.Invoke(initialVector3D.Lerp(targetVector3D, t)));
{
Boxed<Vector3D> boxedInitial = boxedVector3DPool.Get(initialVector3D);
Boxed<Vector3D> boxedTarget = boxedVector3DPool.Get(targetVector3D);
ITween tween = tweenManager.StartTween(duration, t => setMethod?.Invoke(boxedInitial.Value.Lerp(boxedTarget.Value, t)));
tween.OnComplete(() =>
{
boxedVector3DPool.Return(boxedInitial);
boxedVector3DPool.Return(boxedTarget);
});
return tween;
}
}