-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} Delay import
#13843
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
{Core} Delay import
#13843
Conversation
| except Exception as ex: | ||
| # Delay the import and mimic an exception handler | ||
| from msrest.exceptions import ValidationError | ||
| if isinstance(ex, ValidationError): | ||
| logger.debug('Validation error in %s.', str(validator)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mimic the behavior of
azure-cli/src/azure-cli-core/azure/cli/core/util.py
Lines 58 to 63 in e6e437a
| def handle_exception(ex): # pylint: disable=too-many-return-statements | |
| # For error code, follow guidelines at https://docs.python.org/2/library/sys.html#sys.exit, | |
| from jmespath.exceptions import JMESPathTypeError | |
| from msrestazure.azure_exceptions import CloudError | |
| from msrest.exceptions import HttpOperationError, ValidationError, ClientRequestError | |
| from azure.cli.core.azlogging import CommandLoggerContext |
| if full_id_list: | ||
| setattr(namespace, '_ids', full_id_list) | ||
|
|
||
| from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Migrate from msrestazure.tools to azure.mgmt.core.tools.
|
what's relationship with this PR Performance Boost ? |
This is extracted from #13294 to make reviewing easier. |
haroldrandom
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Learnt a lot!
jsntcy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
Description
Previously during CLI initialization, importing these modules are very time-consuming, but actually often unnecessary:
msrestazure.coreazure.mgmt.coreazure.commonThis PR delays the import until these modules are actually used.
The effect is remarkable: For
az verion -h, the import time dropped from 1.755s to 0.648s.Before:

After:

Testing Guide
Generate the import time graph with