Skip to content

Perf: CosmosQueryExecutionContextFactory accesses PartitionKeyRange MinInclusive/MaxExclusive 6 times during pipeline creation #5753

@kirankumarkolli

Description

@kirankumarkolli

Parent issue: #5747

Problem

CosmosQueryExecutionContextFactory (src/Query/Core/Pipeline/CosmosQueryExecutionContextFactory.cs:515-553) accesses PartitionKeyRange.MinInclusive and .MaxExclusive 6 times when converting ranges to FeedRangeEpk during query pipeline creation. Each access triggers JToken.ToObject<T>() deserialization.

Hot path assessment: WARM

Called once per query execution during pipeline initialization. For applications executing many queries per second, this adds up.

Suggested fix

Cache range.MinInclusive and range.MaxExclusive in local variables, or create a helper method that converts PartitionKeyRange to FeedRangeEpk with a single pair of property accesses.

Lines

  • CosmosQueryExecutionContextFactory.cs:515-516 range.MinInclusive / range.MaxExclusive (passthrough context)
  • CosmosQueryExecutionContextFactory.cs:543-544 range.MinInclusive / range.MaxExclusive (full pipeline, first path)
  • CosmosQueryExecutionContextFactory.cs:552-553 range.MinInclusive / range.MaxExclusive (full pipeline, second path)

Constraint

PartitionKeyRange is in compiled NuGet (Microsoft.Azure.Cosmos.Direct) — fix must be at the call site.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions