Skip to content

Commit

Permalink
chore: fix and expand benchmark test
Browse files Browse the repository at this point in the history
  • Loading branch information
sam committed Jan 17, 2023
1 parent 7f85e18 commit 89f4b02
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules/
sdk.generated.ts
.bundle
*.tgz
cdk.out
cdk.out
stats.html
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# itty-aws

This is a teeny-tiny AWS SDK implementation for TypeScript using [Proxies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) that fits everything into `~40KB`, including all Services and APIs. The name is an homage to the awesome [itty-router](https://github.com/kwhitley/itty-router).
This is a teeny-tiny AWS SDK implementation for TypeScript using [Proxies](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) that fits everything into `~14 KB`, including all Services and APIs. The name is an homage to the awesome [itty-router](https://github.com/kwhitley/itty-router).

> 🛠 This is a highly experimental API, do not use for anything serious.
Expand All @@ -21,8 +21,8 @@ This project aims to eliminate the following issues with the official AWS SDK:

The entire AWS SDK (including all Services and APIs) fits in to a

- Minified bundle size of: `40.4kb`.
- Un-minified bundle size of: `89.6kb`.
- Minified bundle size of: `14.6 KB`.
- Un-minified bundle size of: `26.4 KB`.

> 💪 It is possible to reduce this even further.
Expand Down
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions benchmark/functions/src/v3-mono-handler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { DynamoDB } from "@aws-sdk/client-dynamodb";

const client = new DynamoDB({});

const TableName = process.env.TABLE_NAME!;

export async function handler() {
await client.putItem({
TableName,
Item: {
pk: {
S: "pk",
},
prop: {
S: "value",
},
},
});
}
51 changes: 49 additions & 2 deletions benchmark/infra/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const props = {
memorySize: 512,
};

// Node 18, itty-aws, external @aws-sdk/*
const ittyFunc = new aws_lambda_nodejs.NodejsFunction(stack, "IttyFunc", {
functionName: "benchmark-itty",
runtime: aws_lambda.Runtime.NODEJS_18_X,
Expand All @@ -35,30 +36,76 @@ const ittyFunc = new aws_lambda_nodejs.NodejsFunction(stack, "IttyFunc", {
...props,
});

// Node 16, external "aws-sdk"
const v2Func = new aws_lambda_nodejs.NodejsFunction(stack, "V2", {
functionName: "benchmark-v2",
runtime: aws_lambda.Runtime.NODEJS_16_X,
entry: require.resolve("@benchmark/functions/lib/v2-handler"),
bundling: {
externalModules: ["aws-sdk"],
},
...props,
});

// Node 18, aws-sdk-v3, DynamoDBClient.send API, bundled in
const v3BundledFunc = new aws_lambda_nodejs.NodejsFunction(stack, "V3Bundled", {
functionName: "benchmark-v3-bundled",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/itty-handler"),
entry: require.resolve("@benchmark/functions/lib/v3-handler"),
bundling: {
externalModules: [],
},
...props,
});

// Node 18, aws-sdk-v3, DynamoDBClient.send API, tree-shaken out (using one provided by us)
const v3ExcludedFunc = new aws_lambda_nodejs.NodejsFunction(
stack,
"V3Excluded",
{
functionName: "benchmark-v3-excluded",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/itty-handler"),
entry: require.resolve("@benchmark/functions/lib/v3-handler"),
bundling: {
externalModules: ["@aws-sdk/*"],
},
...props,
}
);

// Node 18, aws-sdk-v3, DynamoDB.putItem (mono API), tree-shaken
const v3ExcludedMonoFunc = new aws_lambda_nodejs.NodejsFunction(
stack,
"V3ExcludedMono",
{
functionName: "benchmark-v3-mono-excluded",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/v3-mono-lambda"),
bundling: {
externalModules: ["@aws-sdk/*"],
},
...props,
}
);

// Node 18, aws-sdk-v3, DynamoDB.putItem (mono API), bundled
const v3BundledMonoFunc = new aws_lambda_nodejs.NodejsFunction(
stack,
"V3BundledMono",
{
functionName: "benchmark-v3-mono-bundled",
runtime: aws_lambda.Runtime.NODEJS_18_X,
entry: require.resolve("@benchmark/functions/lib/v3-mono-lambda"),
bundling: {
externalModules: [],
},
...props,
}
);

table.grantReadWriteData(ittyFunc);
table.grantReadWriteData(v2Func);
table.grantReadWriteData(v3BundledFunc);
table.grantReadWriteData(v3ExcludedFunc);
table.grantReadWriteData(v3ExcludedMonoFunc);
table.grantReadWriteData(v3BundledMonoFunc);
2 changes: 1 addition & 1 deletion scripts/analyze-bundle.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mkdir .bundle

npx esbuild ./src/index.ts --platform=node --bundle --outfile=.bundle/index.js --metafile=.bundle/meta.json
npx esbuild ./src/index.ts --platform=node --bundle --outfile=.bundle/index.js --metafile=.bundle/meta.json --external:@aws-sdk/* --minify

npx esbuild-visualizer --metadata .bundle/meta.json --open

0 comments on commit 89f4b02

Please sign in to comment.