Skip to content

Experimental flag to boost 'package' command performance #7923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 10, 2025

Conversation

eyalroth
Copy link
Contributor

@eyalroth eyalroth commented Mar 6, 2025

Which issue(s) does this change fix?

#4053

Why is this change necessary?

sam package (and deploy) can take an extremely long time.

This happens because the command zips every lambda resource in a template, even if all the lambdas point to the same local path. For instance, with NodeJS lambdas, there are many files involved due to the nature of npm/node, and that puts a serious dent on the disk (especially so in CI environments where SSD is not guarenteed).

How does it address the issue?

Normally, sam build will create a separate directory for each lambda resource in the template. However, there is an experimental flag -- SAM_CLI_BETA_BUILD_PERFORMANCE -- which creates only one shared directory for all the lambdas. This boosts sam build performance tremendously, and it works because in most cases, all lambdas in a project share the same code (just a different handler endpoint).

This PR adds a new flag -- SAM_CLI_BETA_PACKAGE_PERFORMANCE -- that is aimed to work in conjunction with the build performance flag.

All that it does is add a cache that is currently only used by ResourceZip + S3Uploader. The uploader checks if the local path was previously uploaded, and if so, it simply returns the cached upload url.

What side effects does this change have?

Should have no effect as the changes are only enabled when using the new flag.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions github-actions bot added pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Mar 6, 2025
@eyalroth eyalroth force-pushed the experimental-package-performance branch from d585998 to 5164b4c Compare March 6, 2025 15:06
@eyalroth eyalroth marked this pull request as ready for review March 6, 2025 15:08
@eyalroth eyalroth requested a review from a team as a code owner March 6, 2025 15:08
@roger-zhangg
Copy link
Member

roger-zhangg commented Mar 17, 2025

Hi @eyalroth thanks for the PR, I see currently there are few errors in CI, do you mind helping to fix them? The implementation looks well-designed. Before merging, please review the testing practices in our development guide and add appropriate test coverage for these changes. Once the tests are in place, this will be ready to merge

@eyalroth eyalroth force-pushed the experimental-package-performance branch from 5f5d4d5 to 9f608f1 Compare March 29, 2025 14:17
@eyalroth
Copy link
Contributor Author

Thank you @roger-zhangg!

Turns out that when I initially ran make pr, it actually failed but I didn't notice.

It failed regardless of my changes, but because I was running with Python 3.12 (default installed on my MacOS). It took me some time to realize I need to install Python 3.9 and setup the virtual env with it. Only then the tests actually worked. It might be worth updating the development guide with these requirements in mind.

I fixed/added relevant tests, amended the original commit, rebased on latest develop and force-pushed.

make pr passes except for test_import_module_proxy.py test, which I think is not related to my changes and would fail on my machine regardless.

Copy link
Member

@roger-zhangg roger-zhangg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for your contribution!

@vicheey vicheey enabled auto-merge April 9, 2025 22:34
@vicheey vicheey added this pull request to the merge queue Apr 10, 2025
Merged via the queue into aws:develop with commit 13e0356 Apr 10, 2025
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants