-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Describe the feature
Website: https://rolldown.rs/
over the past week I have been building a construct for my CDK project that sits on top of the NodeJsFunction and uses rolldown in order to bundle a lambda function, the rolldown project has comparable interface to esbuild but has significant performance benefits
Here's a local benchmark I did on a Mac that shows the accumulated savings when doing an end to end synth.
Heres a quick implementation styled like the NodejsFunction construct: https://gist.github.com/robert-pitt-foodhub/e06a70cef0121fbed5d37921ed675650
Theres two methods I have explored with this so far:
- CDK Invokes rolldown via
spawnSync/execSync
For our project end to end test + synth CI step went from 28 minutes down to 17 minutes
With this approach, using spawnSync invokes (from node) another node process which bootstraps rolldown over and over again for each lambda that needs to be bundled, this is a similar approach to what the NodeJsFunction is doing right now.
- CDK Invokes rolldown via imported rolldown (esm) module and uses de-asyncify
The idea here is to import rolldown in the construct, and then use rolldown synchronously via it's node api, using this approach further reduces overhead and I was able to bring my test + synth to under 14 minutes.
As you can see, going from 28 minutes down to 14 minutes is a significant improvements, in order to get this working I had to use deasyncify as rolldown doesn't have sync api's, however I have opened an issue for that here: rolldown/rolldown#6631
Use Case
The key use case for this is to ease the developers pain around aws-cdk not being able to bundle lambdas in parallel (due to the nature of how cdk constructs it's tree and executes bundling synchronously.
- Improve synth and deploy performance
- Reduced lambda bundle size due to improved tree shaking
- Reduced infrastructure costs.
Proposed Solution
Extend the NodeJsConsturct to support both rolldown and esbuild
Other Information
Here's an example screenshot of the performance of bundling in CI for the larger lambdas we have:
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
AWS CDK Library version (aws-cdk-lib)
2.187.0
AWS CDK CLI version
2.1030.0 (build e46adaf)
Environment details (OS name and version, etc.)
Apple M2 Max