Skip to content

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

Merged
sriram-mv merged 2 commits intoaws:developfrom
jfuss:make-help-text-faster
Oct 8, 2019
Merged

feat(perf): Improve load time of help text#1444
sriram-mv merged 2 commits intoaws:developfrom
jfuss:make-help-text-faster

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.

@jfuss jfuss force-pushed the make-help-text-faster branch from d9333ad to 8f952cd Compare October 4, 2019 18:17
@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.

2 participants