Skip to content

(lambda): Introduce rolldown.rs bundler as an option along side esbuild #35776

@robert-pitt-foodhub

Description

@robert-pitt-foodhub

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.

Image

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:

  1. CDK Invokes rolldown via spawnSync/execSync

For our project end to end test + synth CI step went from 28 minutes down to 17 minutes

Image Image

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.

  1. 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.

Image

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.

  1. Improve synth and deploy performance
  2. Reduced lambda bundle size due to improved tree shaking
  3. 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:

Image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-lambdaRelated to AWS Lambdaeffort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions