Commit 5afe162
perf(cosmos): strip unused fields from partition key range cache
Strip 9 unused fields from partition key range dicts after fetching
from the service. CollectionRoutingMap only uses 4 fields (id,
minInclusive, maxExclusive, parents) but the service returns 13.
Reduces per-range dict memory by ~40%, measured with tracemalloc
on 150 CosmosClient instances with PPCB enabled:
Test setup:
- Account: ~100 physical partitions, 2 regions, multi-write
- Tool: tracemalloc (retained memory)
- Operations: 1 read_item + 1 upsert_item per client
Results (current memory, MB):
| Clients | 4.15.0 PPCB=True | Patched PPCB=True | PPCB=false | Savings |
|---------|-----------------|------------------|-----------|---------|
| 1 | 14.3 | 14.3 | 14.0 | -0.0 |
| 25 | 23.0 | 20.5 | 17.9 | -2.5 |
| 50 | 31.9 | 27.4 | 21.7 | -4.5 |
| 100 | 44.9 | 39.9 | 29.4 | -4.9 |
| 150 | 63.8 | 52.9 | 36.4 | -10.9 |
PPCB overhead reduction:
| Clients | Before | After | Reduction |
|---------|--------|--------|-----------|
| 25 | 5.1 MB | 2.6 MB | -48% |
| 50 |10.3 MB | 5.7 MB | -44% |
| 100 |15.4 MB |10.5 MB | -31% |
| 150 |27.4 MB |16.5 MB | -39% |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent de23b45 commit 5afe162
2 files changed
Lines changed: 12 additions & 0 deletions
File tree
- sdk/cosmos/azure-cosmos/azure/cosmos/_routing
- aio
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
100 | 106 | | |
101 | 107 | | |
102 | 108 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
85 | 91 | | |
86 | 92 | | |
87 | 93 | | |
| |||
0 commit comments