From ea950d8cec25661c9bac6ba3f9a5d3459dfdea4f Mon Sep 17 00:00:00 2001 From: RamType0 Date: Fri, 28 Aug 2020 17:12:03 +0900 Subject: [PATCH 1/3] Optimize ContinuationQueue and PlayerLoopRunner iteration - Fix failing to eliminate array bounds check in PlayerLoopRunner.RunCore - Reduce number of array bounds check of continuation iteration in ContinuationQueue.RunCore --- .../Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs | 5 +++-- .../Plugins/UniTask/Runtime/Internal/PlayerLoopRunner.cs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs index 30bd737..5458a5d 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs @@ -170,8 +170,8 @@ namespace Cysharp.Threading.Tasks.Internal for (int i = 0; i < actionListCount; i++) { - var action = actionList[i]; - actionList[i] = null; + + ref var action = ref actionList[i];//Reduce array bounds check try { @@ -181,6 +181,7 @@ namespace Cysharp.Threading.Tasks.Internal { UnityEngine.Debug.LogException(ex); } + action = null; } { diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/PlayerLoopRunner.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/PlayerLoopRunner.cs index 621ba5a..28babed 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/PlayerLoopRunner.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/PlayerLoopRunner.cs @@ -143,6 +143,7 @@ namespace Cysharp.Threading.Tasks.Internal { var j = tail - 1; + var loopItems = this.loopItems; // eliminate array-bound check for i for (int i = 0; i < loopItems.Length; i++) { From 1f736afe86e2555409d1f25adb02b56a0f6f11fe Mon Sep 17 00:00:00 2001 From: "Ram.Type-0" Date: Sun, 30 Aug 2020 13:53:29 +0900 Subject: [PATCH 2/3] Revert change for ContinuationQueue.RunCore --- .../Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs index 5458a5d..829b09e 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs @@ -171,8 +171,8 @@ namespace Cysharp.Threading.Tasks.Internal for (int i = 0; i < actionListCount; i++) { - ref var action = ref actionList[i];//Reduce array bounds check - + var action = actionList[i];//Reduce array bounds check + actionList[i] = null; try { action(); @@ -181,7 +181,6 @@ namespace Cysharp.Threading.Tasks.Internal { UnityEngine.Debug.LogException(ex); } - action = null; } { From f1193743c8e7b36e14607cd9ed878230067b901b Mon Sep 17 00:00:00 2001 From: RamType0 Date: Tue, 1 Sep 2020 11:53:10 +0900 Subject: [PATCH 3/3] Remove deprecated comment --- .../Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs index 829b09e..3f2a983 100644 --- a/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs +++ b/src/UniTask/Assets/Plugins/UniTask/Runtime/Internal/ContinuationQueue.cs @@ -171,7 +171,7 @@ namespace Cysharp.Threading.Tasks.Internal for (int i = 0; i < actionListCount; i++) { - var action = actionList[i];//Reduce array bounds check + var action = actionList[i]; actionList[i] = null; try {