Skip to content

Commit

Permalink
Removed allocations happening when a tween was killed (because C# was…
Browse files Browse the repository at this point in the history
… erroneously converting a line of code into an Activator.CreateInstance)
  • Loading branch information
Demigiant committed Dec 7, 2016
1 parent 1b2b216 commit 5922a85
Show file tree
Hide file tree
Showing 53 changed files with 106 additions and 5 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween.dll
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween43.dll
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween43.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween46.dll
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween46.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween50.dll
Binary file not shown.
Binary file modified UnityTests.Unity4/Assets/Demigiant/DOTween/DOTween50.dll.mdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween43.dll
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween43.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween46.dll
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween46.dll.mdb
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween50.dll
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Demigiant/DOTween/DOTween50.dll.mdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/Resources/DOTweenSettings.asset
Binary file not shown.
Binary file modified UnityTests.Unity5/Assets/_Tests PRO/TempPro_B.unity
Binary file not shown.
67 changes: 67 additions & 0 deletions UnityTests.Unity5/Assets/_Tests/AllocationsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEditor;
using DG.Tweening;

public class AllocationsTests : BrainBase
{
public enum AllocationTestType
{
DOMove,
DOPath
}

public AllocationTestType testType;
public Transform[] targets;
public Vector3[] wps;

Tween tween0;

IEnumerator Start()
{
DOTween.Init();
yield return new WaitForSeconds(1);

switch (testType) {
case AllocationTestType.DOMove:
Profiler.BeginSample("Create tween");
// Regular move tweens test
Debug.Log("Create tween");
tween0 = targets[0].DOMoveX(2, 1);
Profiler.EndSample();
yield return null;
Profiler.BeginSample("Kill tween");
Debug.Log("Kill tween");
tween0.Kill();
Profiler.EndSample();

yield return null;

Profiler.BeginSample("Create tween 2");
// Regular move tweens test
Debug.Log("Create tween 2");
tween0 = targets[0].DOMoveX(2, 1);
Profiler.EndSample();
yield return null;
Profiler.BeginSample("Kill tween 2");
Debug.Log("Kill tween 2");
tween0.Kill();
Profiler.EndSample();
break;
case AllocationTestType.DOPath:
// Regular move tweens test
Debug.Log("Create tween");
tween0 = targets[0].DOPath(wps, 1);
yield return null;
Debug.Log("Kill tween");
tween0.Kill();
break;
}

yield return null;
yield return null;
EditorApplication.isPaused = true;
}
}
12 changes: 12 additions & 0 deletions UnityTests.Unity5/Assets/_Tests/AllocationsTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
8 changes: 8 additions & 0 deletions UnityTests.Unity5/Assets/_Tests/AllocationsTests.unity.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified UnityTests.Unity5/ProjectSettings/GraphicsSettings.asset
Binary file not shown.
Binary file modified UnityTests.Unity5/ProjectSettings/ProjectSettings.asset
Binary file not shown.
3 changes: 1 addition & 2 deletions UnityTests.Unity5/ProjectSettings/ProjectVersion.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
m_EditorVersion: 5.4.1f1
m_StandardAssetsVersion: 0
m_EditorVersion: 5.5.0f3
3 changes: 2 additions & 1 deletion _DOTween.Assembly/DOTween/Core/TweenerCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ internal sealed override void Reset()
base.Reset();

if (tweenPlugin != null) tweenPlugin.Reset(this);
plugOptions = new TPlugOptions();
// plugOptions = new TPlugOptions(); // Generates GC because converts to an Activator.CreateInstance
plugOptions = Utils.InstanceCreator<TPlugOptions>.Create(); // Fixes GC allocation using workaround
getter = null;
setter = null;
hasManuallySetStartValue = false;
Expand Down
14 changes: 14 additions & 0 deletions _DOTween.Assembly/DOTween/Core/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// License Copyright (c) Daniele Giardini.
// This work is subject to the terms at http://dotween.demigiant.com/license.php

using System;
using System.Linq.Expressions;
using UnityEngine;

namespace DG.Tweening.Core
Expand Down Expand Up @@ -32,5 +34,17 @@ internal static float Angle2D(Vector3 from, Vector3 to)
ang *= -1f;
return ang;
}

// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
// ███ INTERNAL CLASSES ████████████████████████████████████████████████████████████████████████████████████████████████
// █████████████████████████████████████████████████████████████████████████████████████████████████████████████████████

// Uses code from BK > http://stackoverflow.com/a/1280832
public class InstanceCreator<T> where T : new()
{
static readonly Expression<Func<T>> _TExpression = () => new T();
static readonly Func<T> _TBuilder = _TExpression.Compile();
public static T Create() { return _TBuilder(); }
}
}
}
2 changes: 1 addition & 1 deletion _DOTween.Assembly/DOTween/DOTween.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace DG.Tweening
public class DOTween
{
/// <summary>DOTween's version</summary>
public static readonly string Version = "1.1.340";
public static readonly string Version = "1.1.500";

///////////////////////////////////////////////
// Options ////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion _DOTween.Assembly/DOTween43/DOTween43.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="UnityEngine">
<HintPath>C:\Program Files (x86)\Unity 45\Editor\Data\Managed\UnityEngine.dll</HintPath>
<HintPath>C:\Program Files (x86)\Unity 46\Editor\Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
Expand Down
Binary file modified _DOTween.Assembly/bin/DOTween.dll
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween.dll.mdb
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween43.dll
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween43.dll.mdb
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween46.dll
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween46.dll.mdb
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween50.dll
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/DOTween50.dll.mdb
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/Editor/DOTweenEditor.dll
Binary file not shown.
Binary file modified _DOTween.Assembly/bin/Editor/DOTweenEditor.dll.mdb
Binary file not shown.

0 comments on commit 5922a85

Please sign in to comment.