[aws-lambda-nodejs] Bundling performance issues
See original GitHub issue❓ General Issue
The Question
In my stack I’ve created several lamdas using the new NodejsFunction from @aws-cdk/aws-lambda-nodejs
. Functionally everything works fine, code in bundled with Parcel and the stack deploys without issues. There are however two (Parcel related?) performance issues:
- Bundling seems quite slow, my lambda has a few dependencies and it takes about 20 seconds to bundle it.
- When performing multiple tests for the same stack, tests are slow as the lambda bundling isn’t cached.
I’m wondering if this is the expected performance or if I’m missing something? I did some tests with webpack to manually bundle the Lambdas, this is about 3 times faster than webpack. I’m also wondering about the caching feature in Parcel, shouldn’t the second performance issue be tackled it?
How to reproduce
I’ve created a simple sample app to show the issue: https://github.com/jaapvanblaaderen/cdk-lambda-bundling-performance
The app contains a single stack with one lambda that’s referenced in two tests. In the test output you can observe that bundling an empty lambda function takes about 8 seconds (initially slow) and for the second test it’s still around 6-7 seconds (no/bad caching?).
Bundling asset simple-stack/HandlerLambda/Code/Stage...
RUNS lib/simple-stack.test.ts
✨ Built in 8.01s
Bundling asset simple-stack/HandlerLambda/Code/Stage...
RUNS lib/simple-stack.test.ts
✨ Built in 6.66s
PASS lib/simple-stack.test.ts (21.056 s)
Simple Stack
✓ Should have memory size set to 512MB (9505 ms)
✓ Should use Node 12 as runtime (7459 ms)
Test Suites: 1 passed, 1 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 22.211 s
Ran all test suites.
Environment
- CDK CLI Version: 1.62
- Module Version: 1.62
- Node.js Version: v14.4.0
- OS: OSX Catalina
- Language (Version): TypeScript 4.0.2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:10
- Comments:27 (22 by maintainers)
@floydspace we are going to replace
parcel
withesbuild
while still maintaining local bundling + fallback to Docker approach for the moment. People installingesbuild
will have very fast bundling performances.Let me first draft a PR for this then we can work on it together.
Hey @jaapvanblaaderen . I have implemented a new cdk construct aws-lambda-nodejs-esbuild
See comparison results on my machine:
@aws-cdk/aws-lambda-nodejs
:vs
aws-lambda-nodejs-esbuild
:I forked your sample, so you can see how to migrate
Just saying.