Location
`lib/put.ts:171-180`
Problem
```ts
for (const batchItem of batchToPut) {
const item = facet.in(batchItem); // builds + marshalls PK/SK
const key = facet.pk(batchItem) + facet.sk(batchItem); // recomputes PK/SK as strings
writeRequests[key] = { PutRequest: { Item: item } };
itemsByKey[key] = facet.out(item); // unmarshalls (back to original)
}
```
Per record:
- `facet.in()` runs `buildKey` for PK, SK, and every index PK/SK, then marshalls.
- `facet.pk()` runs `buildKey` for PK again.
- `facet.sk()` runs `buildKey` for SK again.
- `facet.out()` unmarshalls and strips synthetic keys.
Steps 2 and 3 are redundant — the marshalled item already contains `item.PK = { S: ... }` and `item.SK = { S: ... }`. The dedupe key can be read directly:
```ts
const key = (item.PK as { S: string }).S + (item.SK as { S: string }).S;
```
For shard-bearing keys, `buildKey` runs CRC32 per call, so this isn't free.
Fix
Reuse the PK/SK from the marshalled item. While there, consider also whether `facet.out(item)` on an item you just constructed is meaningful — it roundtrips through the validator to produce the "record that would come back", but if `in()` is lossless this is equivalent to the original record. Discussion welcome.
Test plan
Micro-benchmark a 10k-item put. Before vs after. Expect modest improvement (low-single-digit percent, mostly due to skipping CRC32 for sharded facets).
Priority
Low — measurable but not dramatic; cleanup value is bigger than the perf value.
Location
`lib/put.ts:171-180`
Problem
```ts
for (const batchItem of batchToPut) {
const item = facet.in(batchItem); // builds + marshalls PK/SK
const key = facet.pk(batchItem) + facet.sk(batchItem); // recomputes PK/SK as strings
writeRequests[key] = { PutRequest: { Item: item } };
itemsByKey[key] = facet.out(item); // unmarshalls (back to original)
}
```
Per record:
Steps 2 and 3 are redundant — the marshalled item already contains `item.PK = { S: ... }` and `item.SK = { S: ... }`. The dedupe key can be read directly:
```ts
const key = (item.PK as { S: string }).S + (item.SK as { S: string }).S;
```
For shard-bearing keys, `buildKey` runs CRC32 per call, so this isn't free.
Fix
Reuse the PK/SK from the marshalled item. While there, consider also whether `facet.out(item)` on an item you just constructed is meaningful — it roundtrips through the validator to produce the "record that would come back", but if `in()` is lossless this is equivalent to the original record. Discussion welcome.
Test plan
Micro-benchmark a 10k-item put. Before vs after. Expect modest improvement (low-single-digit percent, mostly due to skipping CRC32 for sharded facets).
Priority
Low — measurable but not dramatic; cleanup value is bigger than the perf value.