-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} using threads to build command table for performance #32518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
{Core} using threads to build command table for performance #32518
Conversation
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
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>
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this 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 introduces concurrent module loading using ThreadPoolExecutor to improve Azure CLI command table build performance. The changes parallelize the expensive operation of loading command modules, which is currently a major bottleneck.
Key changes:
- Command modules are now loaded concurrently using threads with a configurable timeout and worker count
- Module loading logic has been refactored into smaller methods for better organization
- A new test ensures command table integrity after the threading changes
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/azure-cli-core/azure/cli/core/init.py | Implements ThreadPoolExecutor-based concurrent module loading with timeout protection, refactors module loading into separate methods (_load_modules, _load_single_module, _process_successful_load, etc.), and adds configuration constants for timeout and thread count |
| src/azure-cli-core/azure/cli/core/tests/test_command_table_integrity.py | Adds integration test to verify command table integrity, checking for duplicates, core command groups, structural integrity, and proper command source attribution |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from azure.cli.core.commands import BLOCKED_MODS | ||
|
|
||
| results = [] | ||
| with ThreadPoolExecutor(max_workers=MAX_WORKER_THREAD_COUNT) as executor: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a command only needs to load one module, does creating a ThreadPoolExecutor and using executor.submit add more overhead compared to running it directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question. Although it only adds around ~10-50 microseconds.
| import traceback | ||
| try: | ||
| start_time = timeit.default_timer() | ||
| module_command_table, module_group_table = _load_module_command_loader(self, args, mod) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a risk of race conditions when loading command_loader with multiple threads? How can we ensure that all loaders are properly registered and that each command is correctly mapped to its corresponding loader?
| loader.loaders.append(command_loader) # This will be used by interactive |
| loader.cmd_to_loader_map[cmd] = [command_loader] |
Related command
Description
This PR aims to speed up the time it takes to re-build the commandIndex. This is currently a major bottleneck to performance.
The most expensive operations in that code path have had concurrency applied using threads (where possible).
Testing scenarios:
az help,version,upgrade, etc).vm create, etc).commandIndex.json(when it doesnt exist)commandIndex.json(PATCH)az helpcorrectly generates command tree._update_command_table_from_modulesis unchangedTesting 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.