Parent issue: #5747
Problem
SessionContainer.ResolvePartitionLocalSessionTokenForGateway() (src/SessionContainer.cs:158-163) accesses PartitionKeyRange.Parents in a loop first checking if Parents != null, then iterating Parents.Count and accessing Parents[parentIndex]. Each access to .Parents triggers JToken.ToObject<Collection<string>>(), deserializing the entire collection from JSON on every access.
Hot path assessment: HOT
Called per-request when using Session consistency (the default consistency level). The method resolves session tokens for gateway-mode requests. With partition splits producing parent chains, this loop can execute multiple times per request.
Suggested fix
Cache request.RequestContext.ResolvedPartitionKeyRange.Parents in a local IReadOnlyList<string> variable before the null check and loop.
Lines
SessionContainer.cs:158 request.RequestContext.ResolvedPartitionKeyRange.Parents != null
SessionContainer.cs:161 request.RequestContext.ResolvedPartitionKeyRange.Parents.Count
SessionContainer.cs:163 request.RequestContext.ResolvedPartitionKeyRange.Parents[parentIndex]
Constraint
PartitionKeyRange is in compiled NuGet (Microsoft.Azure.Cosmos.Direct) fix must be at the call site.
Parent issue: #5747
Problem
SessionContainer.ResolvePartitionLocalSessionTokenForGateway()(src/SessionContainer.cs:158-163) accessesPartitionKeyRange.Parentsin a loop first checking ifParents != null, then iteratingParents.Countand accessingParents[parentIndex]. Each access to.ParentstriggersJToken.ToObject<Collection<string>>(), deserializing the entire collection from JSON on every access.Hot path assessment: HOT
Called per-request when using Session consistency (the default consistency level). The method resolves session tokens for gateway-mode requests. With partition splits producing parent chains, this loop can execute multiple times per request.
Suggested fix
Cache
request.RequestContext.ResolvedPartitionKeyRange.Parentsin a localIReadOnlyList<string>variable before the null check and loop.Lines
SessionContainer.cs:158request.RequestContext.ResolvedPartitionKeyRange.Parents != nullSessionContainer.cs:161request.RequestContext.ResolvedPartitionKeyRange.Parents.CountSessionContainer.cs:163request.RequestContext.ResolvedPartitionKeyRange.Parents[parentIndex]Constraint
PartitionKeyRangeis in compiled NuGet (Microsoft.Azure.Cosmos.Direct) fix must be at the call site.