{Core} reduce DevExtension discovery max_depth from 3 to 2#32994
{Core} reduce DevExtension discovery max_depth from 3 to 2#32994
Conversation
The _collect() helper in DevExtension.get_all() recursively walks directories to find *.egg-info markers. A max_depth of 3 is excessive since standard dev extension layouts place .egg-info at depth 1 (pip install -e) or depth 2 (azure-cli-extensions repo: src/<ext_name>/*.egg-info). Reducing to max_depth=2 eliminates an entire level of recursive os.path.isdir(), glob(), and os.listdir() calls, saving ~30-50 ms on Windows when DEV_EXTENSION_SOURCES is configured.
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
This PR aims to speed up Azure CLI startup when DEV_EXTENSION_SOURCES is configured by reducing the recursive directory-walk depth used to discover dev extensions (*.egg-info markers).
Changes:
- Change
DevExtension.get_all()to call_collect(..., max_depth=2)instead of using the defaultmax_depth=3.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| for item in os.listdir(path): | ||
| _collect(os.path.join(path, item), depth + 1, max_depth) | ||
| for source in DEV_EXTENSION_SOURCES: | ||
| _collect(source) | ||
| _collect(source, max_depth=2) |
There was a problem hiding this comment.
Passing max_depth=2 here prevents discovery of *.egg-info directories that are exactly 2 levels below source. _collect returns immediately when depth == max_depth (before running the glob), so with source/src/<ext>/*.egg-info the <ext> directory is reached at depth=2 and will be skipped entirely. Consider either keeping max_depth=3, or changing _collect so the depth limit is enforced only for recursion (e.g., allow processing at depth == max_depth but don’t descend further).
| for source in DEV_EXTENSION_SOURCES: | ||
| _collect(source) | ||
| _collect(source, max_depth=2) |
There was a problem hiding this comment.
This change alters dev extension discovery behavior, but the existing core extension tests (e.g., src/azure-cli-core/azure/cli/core/tests/test_extension.py) don’t appear to cover DevExtension.get_all() or DEV_EXTENSION_SOURCES. Adding a focused unit test that sets DEV_EXTENSION_SOURCES to a temp directory and verifies discovery for layouts at depth 1 and depth 2 would prevent regressions around the depth limit.
Related command
Description
The
_collect()helper inDevExtension.get_all()recursively walks directories to find*.egg-infomarkers. A max_depth of 3 is excessive since standard dev extension layouts place .egg-info at depth 1 (pip install -e) or depth 2 (azure-cli-extensions repo: src/<ext_name>/*.egg-info).Reducing to max_depth=2 eliminates an entire level of recursive
os.path.isdir(),glob(), andos.listdir()calls, saving ~30-50 ms on Windows whenDEV_EXTENSION_SOURCESis configured.Before:

After:

Testing Guide
History Notes
[Component Name 1] BREAKING CHANGE:
az command a: Make some customer-facing breaking change[Component Name 2]
az command b: Add some customer-facing featureThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.