Skip to content

Added cache for computation of partition keys#6719

Open
RanVaknin wants to merge 4 commits intomasterfrom
rvaknin/ddb-optimization-partitionKey-Cache
Open

Added cache for computation of partition keys#6719
RanVaknin wants to merge 4 commits intomasterfrom
rvaknin/ddb-optimization-partitionKey-Cache

Conversation

@RanVaknin
Copy link
Copy Markdown
Contributor

@RanVaknin RanVaknin commented Feb 5, 2026

The DDB Enhanced Client originally used direct field access to retrieve single partition key names from table metadata on every operation. PR #6574 extended this to support composite keys (up to 4 partition + 4 sort keys) by introducing stream processing to extract key names from lists of metadata objects.

Profiling revealed this stream processing is a performance bottleneck. For smaller payload this bottleneck accounts for roughly 20%~ of overall CPU time, with larger and more nested the payloads, the performance profile shifts away from this (for example an item with 80 nested objects that is 4 levels deep this accounts for 4%~ of overall CPU time).

In the current implementation Key.keyMap() is repeatedly calling indexPartitionKeys() to build request key maps for every operation. This PR adds a cache to StaticTableMetadata that computes the key name lists once on first access and return the cached results on subsequent access.

Design Considerations:

Do we need a bounded cache?

While technically nothing prevents the user from creating an infinite amount of indexes, the DDB service side limits on the number of indexes per table:

Since StaticTableMetadata is immutable, the cache contents are fixed for the lifetime of the instance.

Flamegraphs:

Before:

image

After:

image
Operation Size Master (us/op) Optimization (us/op) Improvement
Delete TINY 0.396 0.263 -33.59%
Delete SMALL 0.387 0.26 -32.82%
Delete HUGE 0.392 0.263 -32.91%
Delete HUGE_FLAT 0.397 0.262 -34.01%
Get TINY 0.462 0.312 -32.47%
Get SMALL 0.975 0.695 -28.72%
Get HUGE 10.198 9.289 -8.91%
Get HUGE_FLAT 3.024 2.698 -10.78%
Put TINY 0.688 0.552 -19.77%
Put SMALL 1.284 1.108 -13.71%
Put HUGE 13.482 13.047 -3.23%
Put HUGE_FLAT 7.595 7.301 -3.87%
Query TINY 2.557 2.339 -8.53%
Query SMALL 4.142 3.923 -5.29%
Query HUGE 31.065 30.026 -3.34%
Query HUGE_FLAT 8.975 9.202 2.53%
Scan TINY 1.080 1.082 0.19%
Scan SMALL 2.479 2.585 4.28%
Scan HUGE 30.366 29.667 -2.30%
Scan HUGE_FLAT 8.105 8.273 2.07%
Update TINY 1.277 1.247 -2.35%
Update SMALL 9.241 9.122 -1.29%
Update HUGE 39.486 38.822 -1.68%
Update HUGE_FLAT 232.677 232.115 -0.24%
@RanVaknin RanVaknin marked this pull request as ready for review February 6, 2026 04:05
@RanVaknin RanVaknin requested a review from a team as a code owner February 6, 2026 04:05
@RanVaknin RanVaknin added changelog-not-required Indicate changelog entry is not required for a specific PR no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required labels Feb 6, 2026
@RanVaknin RanVaknin removed changelog-not-required Indicate changelog entry is not required for a specific PR labels Feb 23, 2026
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
54.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required

2 participants