Skip to content

{Core} reduce DevExtension discovery max_depth from 3 to 2#32994

Draft
ReaNAiveD wants to merge 1 commit intoAzure:devfrom
ReaNAiveD:perf/reduce-dev-extension-max-depth
Draft

{Core} reduce DevExtension discovery max_depth from 3 to 2#32994
ReaNAiveD wants to merge 1 commit intoAzure:devfrom
ReaNAiveD:perf/reduce-dev-extension-max-depth

Conversation

@ReaNAiveD
Copy link
Member

Related command

Description

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.

Before:
image

After:
image

Testing Guide

(venv) PS C:\Users\qinkaiwu\Repo\azure-cli> hyperfine --warmup 2 --runs 10 -n "dev (baseline, max_depth=3)" --prepare "git checkout dev" "az extension --help" -n "fix (max_depth=2)" --prepare "git checkout perf/reduce-dev-extension-max-depth" "az extension --help" --export-markdown benchmark_labeled.md
Benchmark 1: dev (baseline, max_depth=3)                                                                                                                                                                                                                                                                                                                    
  Time (mean ± σ):      1.316 s ±  0.102 s    [User: 0.429 s, System: 0.507 s]                                                                                                                                                                                                                                                                              
  Range (min … max):    1.214 s …  1.504 s    10 runs

Benchmark 2: fix (max_depth=2)
  Time (mean ± σ):      1.233 s ±  0.065 s    [User: 0.426 s, System: 0.443 s]                                                                                                                                                                                                                                                                              
  Range (min … max):    1.132 s …  1.326 s    10 runs

Summary
  fix (max_depth=2) ran
    1.07 ± 0.10 times faster than dev (baseline, max_depth=3)

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 feature


This checklist is used to make sure that common guidelines for a pull request are followed.

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.
@ReaNAiveD ReaNAiveD self-assigned this Mar 20, 2026
Copilot AI review requested due to automatic review settings March 20, 2026 06:26
@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Mar 20, 2026

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.13
️✔️acs
️✔️latest
️✔️3.12
️✔️3.13
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.13
️✔️ams
️✔️latest
️✔️3.12
️✔️3.13
️✔️apim
️✔️latest
️✔️3.12
️✔️3.13
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.13
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️aro
️✔️latest
️✔️3.12
️✔️3.13
️✔️backup
️✔️latest
️✔️3.12
️✔️3.13
️✔️batch
️✔️latest
️✔️3.12
️✔️3.13
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.13
️✔️billing
️✔️latest
️✔️3.12
️✔️3.13
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.13
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.13
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.13
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.13
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.13
️✔️config
️✔️latest
️✔️3.12
️✔️3.13
️✔️configure
️✔️latest
️✔️3.12
️✔️3.13
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.13
️✔️container
️✔️latest
️✔️3.12
️✔️3.13
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.13
️✔️core
️✔️latest
️✔️3.12
️✔️3.13
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.13
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.13
️✔️dls
️✔️latest
️✔️3.12
️✔️3.13
️✔️dms
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.13
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.13
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.13
️✔️find
️✔️latest
️✔️3.12
️✔️3.13
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.13
️✔️identity
️✔️latest
️✔️3.12
️✔️3.13
️✔️iot
️✔️latest
️✔️3.12
️✔️3.13
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.13
️✔️lab
️✔️latest
️✔️3.12
️✔️3.13
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.13
️✔️maps
️✔️latest
️✔️3.12
️✔️3.13
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.13
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.13
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.13
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.13
️✔️network
️✔️latest
️✔️3.12
️✔️3.13
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.13
️✔️postgresql
️✔️latest
️✔️3.12
️✔️3.13
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.13
️✔️profile
️✔️latest
️✔️3.12
️✔️3.13
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.13
️✔️redis
️✔️latest
️✔️3.12
️✔️3.13
️✔️relay
️✔️latest
️✔️3.12
️✔️3.13
️✔️resource
️✔️latest
️✔️3.12
️✔️3.13
️✔️role
️✔️latest
️✔️3.12
️✔️3.13
️✔️search
️✔️latest
️✔️3.12
️✔️3.13
️✔️security
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.13
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.13
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.13
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.13
️✔️sql
️✔️latest
️✔️3.12
️✔️3.13
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.13
️✔️storage
️✔️latest
️✔️3.12
️✔️3.13
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.13
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.13
️✔️util
️✔️latest
️✔️3.12
️✔️3.13
️✔️vm
️✔️latest
️✔️3.12
️✔️3.13

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Mar 20, 2026

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan
Copy link
Collaborator

yonzhan commented Mar 20, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link

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).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 default max_depth=3.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 268 to +271
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)
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines 270 to +271
for source in DEV_EXTENSION_SOURCES:
_collect(source)
_collect(source, max_depth=2)
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot Core CLI core infrastructure do-not-merge Installation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants