AzureAD / microsoft-authentication-library-for-python

Microsoft Authentication Library (MSAL) for Python makes it easy to authenticate to Microsoft Entra ID. General docs are available here https://learn.microsoft.com/entra/msal/python/ Stable APIs are documented here https://msal-python.readthedocs.io. Questions can be asked on www.stackoverflow.com with tag "msal" + "python".
https://stackoverflow.com/questions/tagged/azure-ad-msal+python
Other
788 stars 194 forks source link

MSAL can consider using lazy import for `request`, `jwt` #423

Closed jiasli closed 2 years ago

jiasli commented 2 years ago

Describe the bug

Importing MSAL is can cost ~300ms on Windows due to some heavy libraries like request and jwt:

python -X importtime -c "import msal"  2>perf.log; tuna .\perf.log

image

MSAL can consider using lazy import for these libraries so that importing MSAL can be lightweight. (Azure CLI lazily imports MSAL: https://github.com/Azure/azure-cli/pull/19898)

rayluo commented 2 years ago

@jiasli , your screenshot indicated that the requests and jwt combined for 2/3 of the msal import time. The PR above is able to remove those 2 parts from the tuna chart, however the overall import time was only cut short by 1/3, rather than 2/3. Still better than the current situation. :-/