Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: Adds query improvement to avoid ImmutableDictionary #2861

Merged
merged 5 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions Microsoft.Azure.Cosmos/src/ChangeFeed/ChangeFeedPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Microsoft.Azure.Cosmos.ChangeFeed
{
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using Microsoft.Azure.Cosmos.CosmosElements;

Expand All @@ -24,7 +25,7 @@ sealed class ChangeFeedPage
double requestCharge,
string activityId,
ChangeFeedCrossFeedRangeState state,
ImmutableDictionary<string, string> additionalHeaders)
IReadOnlyDictionary<string, string> additionalHeaders)
{
this.Documents = documents ?? throw new ArgumentOutOfRangeException(nameof(documents));
this.NotModified = notModified;
Expand All @@ -44,13 +45,13 @@ sealed class ChangeFeedPage

public ChangeFeedCrossFeedRangeState State { get; }

public ImmutableDictionary<string, string> AdditionalHeaders { get; }
public IReadOnlyDictionary<string, string> AdditionalHeaders { get; }

public static ChangeFeedPage CreateNotModifiedPage(
double requestCharge,
string activityId,
ChangeFeedCrossFeedRangeState state,
ImmutableDictionary<string, string> additionalHeaders)
IReadOnlyDictionary<string, string> additionalHeaders)
{
return new ChangeFeedPage(CosmosArray.Empty, notModified: true, requestCharge, activityId, state, additionalHeaders);
}
Expand All @@ -59,8 +60,8 @@ sealed class ChangeFeedPage
CosmosArray documents,
double requestCharge,
string activityId,
ChangeFeedCrossFeedRangeState state,
ImmutableDictionary<string, string> additionalHeaders)
ChangeFeedCrossFeedRangeState state,
IReadOnlyDictionary<string, string> additionalHeaders)
{
return new ChangeFeedPage(documents, notModified: false, requestCharge, activityId, state, additionalHeaders);
}
Expand Down
6 changes: 3 additions & 3 deletions Microsoft.Azure.Cosmos/src/Pagination/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal abstract class Page<TState>
Microsoft.Azure.Documents.HttpConstants.HttpHeaders.ActivityId,
}.ToImmutableHashSet();

private static readonly ImmutableDictionary<string, string> EmptyDictionary = new Dictionary<string, string>().ToImmutableDictionary();
private static readonly IReadOnlyDictionary<string, string> EmptyDictionary = new Dictionary<string, string>();

protected Page(
double requestCharge,
Expand All @@ -44,14 +44,14 @@ internal abstract class Page<TState>
}
#endif

this.AdditionalHeaders = additionalHeaders == null ? EmptyDictionary : additionalHeaders.ToImmutableDictionary();
this.AdditionalHeaders = additionalHeaders ?? EmptyDictionary;
sourabh1007 marked this conversation as resolved.
Show resolved Hide resolved
}

public double RequestCharge { get; }

public string ActivityId { get; }

public ImmutableDictionary<string, string> AdditionalHeaders { get; }
public IReadOnlyDictionary<string, string> AdditionalHeaders { get; }

public TState State { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public override async ValueTask<bool> MoveNextAsync(ITrace trace)

double requestCharge = 0;
long responseLengthBytes = 0;
ImmutableDictionary<string, string> additionalHeaders = null;
IReadOnlyDictionary<string, string> additionalHeaders = null;
while (await this.inputStage.MoveNextAsync(trace))
{
TryCatch<QueryPage> tryGetPageFromSource = this.inputStage.Current;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public override async ValueTask<bool> MoveNextAsync(ITrace trace)

double requestCharge = 0.0;
long responseLengthInBytes = 0;
ImmutableDictionary<string, string> addtionalHeaders = null;
IReadOnlyDictionary<string, string> addtionalHeaders = null;

while (await this.inputStage.MoveNextAsync(trace))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal sealed class SkipEmptyPageQueryPipelineStage : IQueryPipelineStage
private readonly IQueryPipelineStage inputStage;
private double cumulativeRequestCharge;
private long cumulativeResponseLengthInBytes;
private ImmutableDictionary<string, string> cumulativeAdditionalHeaders;
private IReadOnlyDictionary<string, string> cumulativeAdditionalHeaders;
private CancellationToken cancellationToken;
private bool returnedFinalStats;

Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/ReadFeed/ReadFeedPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sealed class ReadFeedPage
double requestCharge,
string activityId,
ReadFeedCrossFeedRangeState? state,
ImmutableDictionary<string, string> additionalHeaders)
IReadOnlyDictionary<string, string> additionalHeaders)
{
this.Documents = documents ?? throw new ArgumentNullException(nameof(documents));
this.RequestCharge = requestCharge < 0 ? throw new ArgumentOutOfRangeException(nameof(requestCharge)) : requestCharge;
Expand All @@ -41,6 +41,6 @@ sealed class ReadFeedPage

public ReadFeedCrossFeedRangeState? State { get; }

public ImmutableDictionary<string, string> AdditionalHeaders { get; }
public IReadOnlyDictionary<string, string> AdditionalHeaders { get; }
}
}