diff --git a/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/ExecutionState.cs b/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/ExecutionState.cs index cbca8269a81..e1018c02b9f 100644 --- a/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/ExecutionState.cs +++ b/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/ExecutionState.cs @@ -1,4 +1,5 @@ using System.Collections.Concurrent; +using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using HotChocolate.Fusion.Execution.Nodes; @@ -164,9 +165,11 @@ public void CompleteNode( { if (result.DependentsToExecute.Length > 0) { + var dependentsToExecute = result.DependentsToExecute; + foreach (var dependent in node.Dependents) { - if (!result.DependentsToExecute.Contains(dependent)) + if (!ContainsDependent(dependentsToExecute, dependent)) { SkipNode(context, dependent); } @@ -358,6 +361,23 @@ private bool IsInBacklog(int nodeId) => (uint)nodeId < (uint)_nodeStates.Length && _nodeStates[nodeId] == NodeStateBacklog; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static bool ContainsDependent( + ImmutableArray dependentsToExecute, + ExecutionNode dependent) + { + return dependentsToExecute.Length switch + { + 1 => ReferenceEquals(dependentsToExecute[0], dependent), + 2 => ReferenceEquals(dependentsToExecute[0], dependent) + || ReferenceEquals(dependentsToExecute[1], dependent), + 3 => ReferenceEquals(dependentsToExecute[0], dependent) + || ReferenceEquals(dependentsToExecute[1], dependent) + || ReferenceEquals(dependentsToExecute[2], dependent), + _ => dependentsToExecute.Contains(dependent) + }; + } + private void AddToBacklog(ExecutionNode node) { var nodeId = node.Id; diff --git a/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Selection.cs b/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Selection.cs index 7eb3b4f51d0..728dc015d4b 100644 --- a/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Selection.cs +++ b/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/Selection.cs @@ -124,11 +124,13 @@ public bool IsIncluded(ulong includeFlags) || (flags3 & includeFlags) == flags3; } - var span = _includeFlags.AsSpan(); + var includeFlagsArray = _includeFlags; - for (var i = 0; i < span.Length; i++) + for (var i = 0; i < includeFlagsArray.Length; i++) { - if ((span[i] & includeFlags) == span[i]) + var current = includeFlagsArray[i]; + + if ((current & includeFlags) == current) { return true; } diff --git a/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/SelectionSetLookup.cs b/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/SelectionSetLookup.cs index b52562055c6..02ace543707 100644 --- a/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/SelectionSetLookup.cs +++ b/src/HotChocolate/Fusion/src/Fusion.Execution/Execution/Nodes/SelectionSetLookup.cs @@ -84,13 +84,7 @@ public static SelectionLookup Create(SelectionSet selectionSet) [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryGetSelection(ReadOnlySpan name, [NotNullWhen(true)] out Selection? selection) { - var table = _table.AsSpan(); - - if (table.Length == 0) - { - selection = default!; - return false; - } + var table = _table; var hashCode = ComputeHash(name, _seed); var index = hashCode & _mask;