Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,27 @@ public IncrementalPlan(
DeliveryGroups = deliveryGroups;
Requirements = requirements.IsDefault ? [] : requirements;
_nodesById = CreateNodeLookup(allNodes);

if (!allNodes.IsDefaultOrEmpty)
{
foreach (var node in allNodes)
{
if (node is NodeFieldExecutionNode)
{
UsesDynamicSchemaNames = true;
}

if (node is OperationBatchExecutionNode or ApolloOperationBatchExecutionNode)
{
UsesBatchNodes = true;
}

if (UsesDynamicSchemaNames && UsesBatchNodes)
{
break;
}
}
}
}

/// <summary>
Expand Down Expand Up @@ -92,6 +113,10 @@ public IncrementalPlan(
/// </summary>
public int MaxNodeId => _nodesById.Length > 0 ? _nodesById.Length - 1 : 0;

internal bool UsesDynamicSchemaNames { get; }

internal bool UsesBatchNodes { get; }

/// <summary>
/// Gets the child incremental plans for this plan. Incremental plans do not
/// contain child plan objects; the root <see cref="OperationPlan"/> exposes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,27 @@ private OperationPlan(
IncrementalPlans = incrementalPlans;
_nodesById = CreateNodeLookup(allNodes);
MaxNodeId = _nodesById.Length > 0 ? _nodesById.Length - 1 : 0;

if (!allNodes.IsDefaultOrEmpty)
{
foreach (var node in allNodes)
{
if (node is NodeFieldExecutionNode)
{
UsesDynamicSchemaNames = true;
}

if (node is OperationBatchExecutionNode or ApolloOperationBatchExecutionNode)
{
UsesBatchNodes = true;
}

if (UsesDynamicSchemaNames && UsesBatchNodes)
{
break;
}
}
}
}

/// <summary>
Expand Down Expand Up @@ -100,6 +121,10 @@ public IReadOnlyList<VariableDefinitionNode> VariableDefinitions
/// </summary>
public int MaxNodeId { get; }

internal bool UsesDynamicSchemaNames { get; }

internal bool UsesBatchNodes { get; }

/// <summary>
/// Retrieves the execution node associated with a plan node identifier.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ internal void Initialize(
CancellationTokenSource cancellationTokenSource,
MemoryArena? memory = null)
{
_activeNodeSlotCount = 0;
_usesDynamicSchemaNames = true;
_usesBatchNodes = true;

ArgumentNullException.ThrowIfNull(requestContext);
ArgumentNullException.ThrowIfNull(variables);
ArgumentNullException.ThrowIfNull(operationPlan);
Expand All @@ -49,6 +53,20 @@ internal void Initialize(

Variables = variables;
OperationPlan = operationPlan;

switch (operationPlan)
{
case OperationPlan plan:
_usesDynamicSchemaNames = plan.UsesDynamicSchemaNames;
_usesBatchNodes = plan.UsesBatchNodes;
break;

case IncrementalPlan plan:
_usesDynamicSchemaNames = plan.UsesDynamicSchemaNames;
_usesBatchNodes = plan.UsesBatchNodes;
break;
}

IncludeFlags = operationPlan.Operation.CreateIncludeFlags(variables);
DeferFlags = operationPlan.Operation.CreateDeferFlags(variables);
_collectTelemetry = requestContext.CollectOperationPlanTelemetry();
Expand All @@ -67,7 +85,9 @@ internal void Initialize(

_executionState.Initialize(_collectTelemetry, cancellationTokenSource);

EnsureNodeArrayCapacity(operationPlan.MaxNodeId);
var maxNodeId = operationPlan.MaxNodeId;
EnsureNodeArrayCapacity(maxNodeId);
_activeNodeSlotCount = maxNodeId + 1;
}

/// <summary>
Expand Down Expand Up @@ -106,19 +126,36 @@ internal void ReturnEngineCancellation()
/// </summary>
internal void Clean()
{
DisposeNodeState();
var activeNodeSlotCount = _activeNodeSlotCount;

if (_nodeSlotCapacity > 0)
if (activeNodeSlotCount > 0)
{
Array.Clear(_nodesToComplete, 0, _nodeSlotCapacity);
Array.Clear(_schemaNames, 0, _nodeSlotCapacity);
Array.Clear(_skippedDefinitions, 0, _nodeSlotCapacity);
Array.Clear(_batchRequestErrors, 0, _nodeSlotCapacity);
Array.Clear(_variableValueSets, 0, _nodeSlotCapacity);
Array.Clear(_transportUris, 0, _nodeSlotCapacity);
Array.Clear(_transportContentTypes, 0, _nodeSlotCapacity);
DisposeNodeState(activeNodeSlotCount);
Array.Clear(_nodesToComplete, 0, activeNodeSlotCount);

if (_usesDynamicSchemaNames)
{
Array.Clear(_schemaNames, 0, activeNodeSlotCount);
}

if (_usesBatchNodes)
{
Array.Clear(_skippedDefinitions, 0, activeNodeSlotCount);
Array.Clear(_batchRequestErrors, 0, activeNodeSlotCount);
}

if (_collectTelemetry)
{
Array.Clear(_variableValueSets, 0, activeNodeSlotCount);
Array.Clear(_transportUris, 0, activeNodeSlotCount);
Array.Clear(_transportContentTypes, 0, activeNodeSlotCount);
}
}

_activeNodeSlotCount = 0;
_usesDynamicSchemaNames = true;
_usesBatchNodes = true;

_resultStore.Clean(256, 256);
_executionState.Clean();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ public sealed partial class OperationPlanContext : IFeatureProvider, IAsyncDispo
private readonly INodeIdParser _nodeIdParser;
private readonly IErrorHandler _errorHandler;
private bool _collectTelemetry;
private bool _usesDynamicSchemaNames;
private bool _usesBatchNodes;
#pragma warning disable IDE0370 // Remove unnecessary suppression
private ISourceSchemaClientScope _clientScope = default!;
#pragma warning restore IDE0370 // Remove unnecessary suppression
private string? _traceId;
private long _start;
private long _clientScopeCreatedAt;
private int _disposed;
private int _activeNodeSlotCount;
private int _nodeSlotCapacity;
private MemoryArena? _memory;
private readonly FixedMemoryArenaSource _memorySource = new();
Expand Down Expand Up @@ -890,28 +893,37 @@ public bool TryParseTypeNameFromId(string id, [NotNullWhen(true)] out string? ty

private void ResetNodeState()
{
Array.Clear(_schemaNames);
Array.Clear(_skippedDefinitions);
Array.Clear(_batchRequestErrors);
var activeNodeSlotCount = _activeNodeSlotCount;

if (_usesDynamicSchemaNames)
{
Array.Clear(_schemaNames, 0, activeNodeSlotCount);
}

if (_usesBatchNodes)
{
Array.Clear(_skippedDefinitions, 0, activeNodeSlotCount);
Array.Clear(_batchRequestErrors, 0, activeNodeSlotCount);
}

if (_collectTelemetry)
{
Array.Clear(_variableValueSets);
Array.Clear(_transportUris);
Array.Clear(_transportContentTypes);
Array.Clear(_variableValueSets, 0, activeNodeSlotCount);
Array.Clear(_transportUris, 0, activeNodeSlotCount);
Array.Clear(_transportContentTypes, 0, activeNodeSlotCount);
}

foreach (var nodeCompletionSet in _nodesToComplete)
for (var i = 0; i < activeNodeSlotCount; i++)
{
nodeCompletionSet?.Reset();
_nodesToComplete[i]?.Reset();
}
}

private void DisposeNodeState()
private void DisposeNodeState(int activeNodeSlotCount)
{
foreach (var nodeCompletionSet in _nodesToComplete)
for (var i = 0; i < activeNodeSlotCount; i++)
{
nodeCompletionSet?.Dispose();
_nodesToComplete[i]?.Dispose();
}
}

Expand Down
Loading
Loading