Skip to content

Commit 56bd775

Browse files
committed
chore(util-dynamodb): add performance test in util-dynamodb
1 parent a4f5454 commit 56bd775

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

codegen/smithy-aws-typescript-codegen/src/main/resources/software/amazon/smithy/aws/typescript/codegen/doc-client-utils.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,19 @@ const processKeyInObj = (obj: any, processFunc: Function, children?: KeyNode[] |
3535
return processObj(obj, processFunc, children);
3636
};
3737

38-
const processKeysInObj = (obj: any, processFunc: Function, keyNodes: KeyNode[]) =>
39-
keyNodes.reduce(
40-
(acc, { key, children }) => ({
41-
...acc,
42-
[key]: processKeyInObj(acc[key], processFunc, children),
43-
}),
44-
obj
45-
);
38+
const processKeysInObj = (obj: any, processFunc: Function, keyNodes: KeyNode[]) => {
39+
const accumulator = { ...obj };
40+
return keyNodes.reduce((acc, { key, children }) => {
41+
acc[key] = processKeyInObj(acc[key], processFunc, children);
42+
return acc;
43+
}, accumulator);
44+
};
4645

4746
const processAllKeysInObj = (obj: any, processFunc: Function, children?: KeyNode[] | AllNodes): any =>
48-
Object.entries(obj).reduce(
49-
(acc, [key, value]) => ({
50-
...acc,
51-
[key]: processKeyInObj(value, processFunc, children),
52-
}),
53-
{}
54-
);
47+
Object.entries(obj).reduce((acc, [key, value]) => {
48+
acc[key] = processKeyInObj(value, processFunc, children);
49+
return acc;
50+
}, {} as any);
5551

5652
export const marshallInput = (obj: any, keyNodes: KeyNode[], options?: marshallOptions) => {
5753
const marshallFunc = (toMarshall: any) => marshall(toMarshall, options);

lib/lib-dynamodb/src/commands/utils.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,19 @@ const processKeyInObj = (obj: any, processFunc: Function, children?: KeyNode[] |
3636
return processObj(obj, processFunc, children);
3737
};
3838

39-
const processKeysInObj = (obj: any, processFunc: Function, keyNodes: KeyNode[]) =>
40-
keyNodes.reduce(
41-
(acc, { key, children }) => ({
42-
...acc,
43-
[key]: processKeyInObj(acc[key], processFunc, children),
44-
}),
45-
obj
46-
);
39+
const processKeysInObj = (obj: any, processFunc: Function, keyNodes: KeyNode[]) => {
40+
const accumulator = { ...obj };
41+
return keyNodes.reduce((acc, { key, children }) => {
42+
acc[key] = processKeyInObj(acc[key], processFunc, children);
43+
return acc;
44+
}, accumulator);
45+
};
4746

4847
const processAllKeysInObj = (obj: any, processFunc: Function, children?: KeyNode[] | AllNodes): any =>
49-
Object.entries(obj).reduce(
50-
(acc, [key, value]) => ({
51-
...acc,
52-
[key]: processKeyInObj(value, processFunc, children),
53-
}),
54-
{}
55-
);
48+
Object.entries(obj).reduce((acc, [key, value]) => {
49+
acc[key] = processKeyInObj(value, processFunc, children);
50+
return acc;
51+
}, {} as any);
5652

5753
export const marshallInput = (obj: any, keyNodes: KeyNode[], options?: marshallOptions) => {
5854
const marshallFunc = (toMarshall: any) => marshall(toMarshall, options);

packages/util-dynamodb/src/convertToNative.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ describe("convertToNative", () => {
214214
const output = { numberKey: { value: "1.01" }, bigintKey: { value: "9007199254740996" } };
215215
expect(convertToNative({ M: input }, { wrapNumbers: true })).toEqual(output);
216216
});
217+
218+
it(`testing map with big objects`, () => {
219+
const input = Array.from({ length: 100000 }, (_, idx) => [idx, { N: "1.00" }]).reduce((acc, [key, value]) => {
220+
acc[key as unknown as string] = value;
221+
return acc;
222+
}, {});
223+
const output = Array.from({ length: 100000 }, (_, idx) => [idx, 1]).reduce((acc, [key, value]) => {
224+
acc[key as unknown as string] = value;
225+
return acc;
226+
}, {});
227+
expect(convertToNative({ M: input })).toEqual(output);
228+
});
217229
});
218230

219231
describe("set", () => {

packages/util-dynamodb/src/convertToNative.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ const convertMap = (
7474
options?: unmarshallOptions
7575
): Record<string, NativeAttributeValue> =>
7676
Object.entries(map).reduce(
77-
(acc: Record<string, NativeAttributeValue>, [key, value]: [string, AttributeValue]) => ({
78-
...acc,
79-
[key]: convertToNative(value, options),
80-
}),
77+
(acc: Record<string, NativeAttributeValue>, [key, value]: [string, AttributeValue]) => (
78+
(acc[key] = convertToNative(value, options)), acc
79+
),
8180
{}
8281
);

0 commit comments

Comments
 (0)