Skip to content

Perf: IRoutingMapProviderExtensions.GetTargetPartitionKeyRangesAsync accesses MaxExclusive in loop #5754

@kirankumarkolli

Description

@kirankumarkolli

Parent issue: #5747

Problem

IRoutingMapProviderExtensions.GetTargetPartitionKeyRangesAsync() (src/Routing/IRoutingMapProviderExtensions.cs:126) accesses PartitionKeyRange.MaxExclusive inside a loop when computing overlapping ranges. Each access triggers JToken.ToObject<T>() deserialization.

Hot path assessment: WARM

Called O(N) per query where N is the number of target partition key ranges. For cross-partition queries targeting many partitions, this can be significant.

Suggested fix

Cache targetRanges.Last().MaxExclusive in a local variable before the comparison, or use Range<string> objects that already have materialized Max values.

Lines

  • IRoutingMapProviderExtensions.cs:126 targetRanges.Last().MaxExclusive

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