Skip to content

Conversation

@mndeveci
Copy link
Contributor

@mndeveci mndeveci commented Jun 4, 2022

Which issue(s) does this change fix?

#3093
#2688

Why is this change necessary?

Previously, SAM CLI improved build performance by introducing de-duplicated & cached builds. These improvements are using copying previously built resources to skip some of the build operations. But runtimes like nodejs might contain lots of files inside node_modules folder which makes copy operation slow.

How does it address the issue?

In order to address this issue, this PR has following improvements;

  • For de-duplicated builds (where multiple functions uses same CodeUri) we will be building into a shared folder and point all of the functions to that folder rather than copying first built function into rest of them.
  • For cached builds, we will be symlinking previously built artifacts to the target folder, instead of copying them.
  • For Auto Dependency Layer (SAM Accelerate feature, where dependencies of a function is moved to a separate layer), we will be symlinking the dependencies to the target layer folder.

What side effects does this change have?

Certain operating systems might not support symlinking correctly. Because of that, we are checking if any errors are thrown with symlink operation, if so we will fall-back to copy.
This feature will also be released behind a feature flag to address some issues before marking it as GA.

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.

@mndeveci mndeveci changed the title feat: de-dup & cached build performance improvements feat: dedup & cached build performance improvements Jun 4, 2022
@github-actions github-actions bot added area/build sam build command pr/internal labels Jun 4, 2022
@mndeveci mndeveci marked this pull request as ready for review July 13, 2022 14:43
return self.functions[0].get_build_dir(artifact_root_dir)
build_dir = self.functions[0].get_build_dir(artifact_root_dir)
if is_experimental_enabled(ExperimentalFlag.BuildImprovements22) and len(self.functions) > 1:
build_dir = f"{build_dir}-Shared"
Copy link
Contributor

@sriram-mv sriram-mv Jul 18, 2022

Choose a reason for hiding this comment

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

How is this suffix "Shared" determined?

Copy link
Contributor

Choose a reason for hiding this comment

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

When determining the artifacts directory that we will have our resultant build in, before we would copy all the contents in the same code URI (technically the same build definition) over and over. Now if there are multiple functions with the same build definition we will just put them into one single shared artifacts directory.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, putting up that comment above the line and also making the suffix a constant string thats defined and importable would be good.

@praneetap
Copy link
Contributor

I wonder if we can recommend this option/flag based on the runtime...if the project is using node, we can probably add a hint to use this in the CLI.

@mildaniel
Copy link
Contributor

I wonder if we can recommend this option/flag based on the runtime...if the project is using node, we can probably add a hint to use this in the CLI.

These changes aren't necessarily runtime-specific except for the accelerate related changes which are only applicable to Python and esbuild.

@mildaniel mildaniel requested a review from sriram-mv July 28, 2022 23:01
self._validate_functions()
return self.functions[0].get_build_dir(artifact_root_dir)
build_dir = self.functions[0].get_build_dir(artifact_root_dir)
if is_experimental_enabled(ExperimentalFlag.BuildPerformance) and len(self.functions) > 1:
Copy link
Contributor

@mildaniel mildaniel Aug 4, 2022

Choose a reason for hiding this comment

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

Add message to customers about this change and add a link to a doc about all the changes that this includes. Will do this in another PR.

Copy link
Contributor

@qingchm qingchm left a comment

Choose a reason for hiding this comment

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

Discussion for review session has been captured in the comments above. The main focus would be to release this feature in the upcoming releases and then construct a corresponding documentation link explaining on the experimental features. With that customers can better understand the improvements.

@mildaniel mildaniel merged commit ee07fea into aws:develop Aug 5, 2022
torresxb1 pushed a commit to torresxb1/aws-sam-cli that referenced this pull request Sep 2, 2022
* create symlink during cached build & use first built folder for de-dup builds

* add experimental flag and unit tests

* add adl use case

* create osutil function

* create osutil function

* update integration tests

* format files

* Rename feature flag

* Add comment and make shared constant

Co-authored-by: Daniel Mil <mladan@amazon.com>
Co-authored-by: Daniel Mil <84205762+mildaniel@users.noreply.github.com>
Co-authored-by: Qingchuan Ma <69653965+qingchm@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/build sam build command pr/internal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants