Skip to content

feat: implement lazy loading for CLI groups#8472

Merged
valerena merged 2 commits into
aws:developfrom
bchampp:chore/lazy-cli-groups
Dec 1, 2025
Merged

feat: implement lazy loading for CLI groups#8472
valerena merged 2 commits into
aws:developfrom
bchampp:chore/lazy-cli-groups

Conversation

@bchampp

@bchampp bchampp commented Dec 1, 2025

Copy link
Copy Markdown
Member

Which issue(s) does this change fix?

Why is this change necessary?

The SAM CLI has many CLI groups now, and we see overhead while running a given command due to SAM needing to import all CLI sub-commands (and the modules they need).

How does it address the issue?

Implementing a lazy CLI group base class based on https://click.palletsprojects.com/en/stable/complex/#lazily-loading-subcommands. This defers imports so we only import the given CLI group when it's the command being run.

What side effects does this change have?

None - defer imports to be lazy loaded. I've added unit tests to validate the --help commands for these CLI groups, but if a requested CLI group doesn't exist (e.g. we're pointing to a non-existing group), the schema generation will fail.

Mandatory Checklist

PRs will only be reviewed after checklist is complete

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 area/pipeline area/schema JSON schema file pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Dec 1, 2025
@bchampp
bchampp marked this pull request as ready for review December 1, 2025 19:12
@bchampp
bchampp requested a review from a team as a code owner December 1, 2025 19:12
reedham-aws
reedham-aws previously approved these changes Dec 1, 2025

@reedham-aws reedham-aws left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving because I think it's good as is, just had one small suggestion

Comment thread schema/make_schema.py Outdated
Comment thread samcli/commands/local/local.py
Vandita2020
Vandita2020 previously approved these changes Dec 1, 2025
@bchampp
bchampp dismissed stale reviews from Vandita2020 and reedham-aws via 1e19ebc December 1, 2025 22:09
@valerena
valerena merged commit 6d54aed into aws:develop Dec 1, 2025
42 checks passed
@roger-zhangg

Copy link
Copy Markdown
Member

Do we have some before/after data comparison?

@bchampp

bchampp commented Dec 1, 2025

Copy link
Copy Markdown
Member Author

Do we have some before/after data comparison?

Yeah - I was able to see about a ~300ms difference calling the --help CLI for a subcommand under local. I had to turn off the proxy module thing that gets added in development mode for it to be realistic since that also adds a lot of overhead.

@bchampp
bchampp deleted the chore/lazy-cli-groups branch December 1, 2025 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/pipeline area/schema JSON schema file 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.

5 participants