Skip to content
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

feat(perf): Improve load time of help text #1444

Merged
merged 2 commits into from
Oct 8, 2019

Conversation

jfuss
Copy link
Contributor

@jfuss jfuss commented Oct 4, 2019

Issue #, if available:
N/A

Description of changes:

sam --help is a very slow operation. Testing on my machine took about ~1.25s. Comparing this the sam build --help, help text was displayed in ~.7s. The main reason for this is due to how python loads modules and click. In order for click to know the help text of each command, click calls list_commands and then get_command for each command in the list. Our get_command implementation will then import the command module and return the cli method. This means a sam --help will end up loading the entire samcli module (or very close to it), while sam build --help will only load the 'build' related modules.

This PR moves, most, of the command module loading from the global package/module scope (file), to specific methods. This reduces both sam --help and sam build --help to .63s and .6s respectfully, a roughly 50% reduction on sam --help.

There could be better ways to lazy load these modules but not currently aware. Since this only moves the imports of some modules to the call of cli method, execution of the commands won't be impacted. This is due to the same loading that was being done in the global scope is now just done a function execution instead. This does not change how we load any of the 'library' code within the cli, only the parts of the code base that are the entry point for a given command (ones annotated with parameters/options/etc).

Checklist:

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

@sriram-mv sriram-mv self-requested a review October 7, 2019 17:30
@sriram-mv sriram-mv merged commit 83d4d49 into aws:develop Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants