feat(perf): Improve load time of help text#1444
Merged
sriram-mv merged 2 commits intoaws:developfrom Oct 8, 2019
Merged
Conversation
d9333ad to
8f952cd
Compare
sriram-mv
approved these changes
Oct 7, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
N/A
Description of changes:
sam --helpis a very slow operation. Testing on my machine took about ~1.25s. Comparing this thesam 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 callslist_commandsand thenget_commandfor each command in the list. Ourget_commandimplementation will then import the command module and return theclimethod. This means asam --helpwill end up loading the entiresamclimodule (or very close to it), whilesam build --helpwill 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 --helpandsam build --helpto .63s and .6s respectfully, a roughly 50% reduction onsam --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
climethod, 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:
make prpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.