Skip to content

Commit c5ac103

Browse files
authored
[Internal] Query: Refactors ParallelCrossPartitionQueryPipelineStage to improve perf (#4548)
* init * revert test * remove sw * nit * cleanup
1 parent 035d229 commit c5ac103

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

Microsoft.Azure.Cosmos/src/Query/Core/Pipeline/CrossPartition/Parallel/ParallelCrossPartitionQueryPipelineStage.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,24 @@ public async ValueTask<bool> MoveNextAsync(ITrace trace, CancellationToken cance
7878
else
7979
{
8080
// left most and any non null continuations
81-
IOrderedEnumerable<FeedRangeState<QueryState>> feedRangeStates = crossPartitionState
82-
.Value
83-
.ToArray()
84-
.OrderBy(tuple => ((FeedRangeEpk)tuple.FeedRange).Range.Min);
81+
FeedRangeState<QueryState>[] feedRangeStates = crossPartitionState.Value.ToArray();
82+
Array.Sort<FeedRangeState<QueryState>>(feedRangeStates, (x, y) => string.CompareOrdinal(((FeedRangeEpk)x.FeedRange).Range.Min, ((FeedRangeEpk)y.FeedRange).Range.Min));
8583

8684
List<ParallelContinuationToken> activeParallelContinuationTokens = new List<ParallelContinuationToken>();
8785
{
88-
FeedRangeState<QueryState> firstState = feedRangeStates.First();
86+
FeedRangeState<QueryState> firstState = feedRangeStates[0];
8987
ParallelContinuationToken firstParallelContinuationToken = new ParallelContinuationToken(
9088
token: firstState.State != null ? ((CosmosString)firstState.State.Value).Value : null,
9189
range: ((FeedRangeEpk)firstState.FeedRange).Range);
9290

9391
activeParallelContinuationTokens.Add(firstParallelContinuationToken);
9492
}
9593

96-
foreach (FeedRangeState<QueryState> feedRangeState in feedRangeStates.Skip(1))
94+
for (int i = 1; i < feedRangeStates.Length; i++)
9795
{
9896
cancellationToken.ThrowIfCancellationRequested();
9997

98+
FeedRangeState<QueryState> feedRangeState = feedRangeStates[i];
10099
if (feedRangeState.State != null)
101100
{
102101
ParallelContinuationToken parallelContinuationToken = new ParallelContinuationToken(

0 commit comments

Comments
 (0)