Skip to content

Commit 895bdfb

Browse files
committed
perf: reduce DevExtension discovery max_depth from 3 to 2
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.
1 parent 9428bc2 commit 895bdfb

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/azure-cli-core/azure/cli/core/extension/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def _collect(path, depth=0, max_depth=3):
268268
for item in os.listdir(path):
269269
_collect(os.path.join(path, item), depth + 1, max_depth)
270270
for source in DEV_EXTENSION_SOURCES:
271-
_collect(source)
271+
_collect(source, max_depth=2)
272272
# https://docs.python.org/3/library/os.html#os.listdir, listdir is in arbitrary order.
273273
# Sort the extensions by name to support overwrite extension feature: https://github.com/Azure/azure-cli/issues/25782.
274274
exts.sort(key=lambda ext: ext.name)

0 commit comments

Comments
 (0)