From ea950d8cec25661c9bac6ba3f9a5d3459dfdea4f Mon Sep 17 00:00:00 2001 From: RamType0 Date: Fri, 28 Aug 2020 17:12:03 +0900 Subject: [PATCH] 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++) {