Skip to content

Perf: AddressResolver.TryResolveServerPartitionAsync triggers JSON deserialization on PartitionKeyRange.Id per request #5750

@kirankumarkolli

Description

@kirankumarkolli

Parent issue: #5747

Problem

AddressResolver.TryResolveServerPartitionAsync() (src/Routing/AddressResolver.cs:497-510) accesses PartitionKeyRange.Id 3 times during address resolution. Since Id inherits from Resource JsonSerializable, each access triggers JToken.ToObject<T>(). This method is called on every single request as part of core routing.

Hot path assessment: HOT

Every SDK operation goes through ResolveAsync() TryResolveServerPartitionAsync(). This is the most frequently executed code path in the SDK.

Suggested fix

Cache range.Id in a local variable at the top of the method before the 3 usages at lines 497, 501, and 510.

Lines

  • AddressResolver.cs:497 routingMap.TryGetInfoByPartitionKeyRangeId(range.Id)
  • AddressResolver.cs:501 new PartitionKeyRangeIdentity(collection.ResourceId, range.Id)
  • AddressResolver.cs:510 new PartitionKeyRangeIdentity(collection.ResourceId, range.Id)

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