Skip to content

Support PEP 420 -- Implicit Namespace Packages #13293

Description

@jiasli

As Python 2 has been deprecated, we should move away from the pkg_resources approach and use PEP 420 -- Implicit Namespace Packages.

Importing pkg_resources will add a 100ms~200ms delay to CLI's loading time.

$ time python -c "import pkg_resources"

real    0m0.153s
user    0m0.137s
sys     0m0.016s
time python -X importtime -m azure.cli version -h 2>perf.log
tuna perf.log

image

This is discussed at pypa/setuptools#510 which affects many projects but still doesn't have a proper fix.

Moreover, on Linux, the wrapper ~/env38/bin/az created by Easy Install also requires pkg_resources:

#!/home/admin/env38/bin/python
# EASY-INSTALL-DEV-SCRIPT: 'azure-cli==2.5.1','az'
__requires__ = 'azure-cli==2.5.1'
__import__('pkg_resources').require('azure-cli==2.5.1')
__file__ = '/home/admin/azure-cli/src/azure-cli/az'
with open(__file__) as f:
    exec(compile(f.read(), __file__, 'exec'))

This makes az installed via azdev even slower.

For comparison, directly run azure.cli:

$ time python -m azure.cli version -h

real    0m0.261s
user    0m0.238s
sys     0m0.024s

Run the Easy Install wrapper:

$ time python ~/env38/bin/az version -h

real    0m0.822s
user    0m0.779s
sys     0m0.044s
python -X importtime ~/env38/bin/az version -h 2>perf.log
tuna perf.log

image

In our Linux release, we package our own wrapper src/azure-cli/az, so it doesn't suffer from the slowness of this Easy Install wrapper.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions