{Core} Use commandIndex caching to improve performance of top-level help commands#32637
{Core} Use commandIndex caching to improve performance of top-level help commands#32637DanielMicrosoft wants to merge 35 commits intoAzure:devfrom
help commands#32637Conversation
️✔️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>
|
help commandhelp commands
help commandshelp commands
… path
- Fixed bug where 'args and '--help' in args or '-h' in args' evaluated incorrectly when args=None
- Added parentheses to ensure proper grouping: 'args and ('--help' in args or '-h' in args ...)'
- Removed 'elif not args' path that was incorrectly showing cached help when args=None
- When args=None, load_command_table should load all commands, not display help
- All test_help.py tests now pass (8/8)
This reverts commit 3f55508.
478fac6 to
16d1c57
Compare
There was a problem hiding this comment.
Pull request overview
This PR implements performance optimization for top-level help commands (az --help and az) by caching help metadata in the CommandIndex. When cached help data is available and valid, the CLI displays it without loading all command modules, significantly improving response time. The implementation adds early-exit logic in the invoker, help data extraction and storage methods, and cached help display functionality.
Changes:
- Added help index caching to CommandIndex with validation based on CLI version and cloud profile
- Implemented early exit path for top-level help requests when cached data is available
- Created cached help display method that replicates the standard help output format
- Added test cleanup to prevent cached test data from polluting production cache
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/azure-cli-core/azure/cli/core/init.py | Added CommandIndex methods for help data storage/retrieval and CommandLoader method to cache help data after loading command table |
| src/azure-cli-core/azure/cli/core/commands/init.py | Implemented early-exit caching path in invoker and help data extraction from parser for initial cache population |
| src/azure-cli-core/azure/cli/core/_help.py | Added cached help display methods that format and print help data without loading modules |
| src/azure-cli-core/azure/cli/core/tests/test_help.py | Added cache cleanup in tearDown to prevent test pollution |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
could you show what the command index with help information currently looks like in the description? thanks a lot. |
| groups, commands = extract_help_index_data(help_file) | ||
|
|
||
| # Store in the command index | ||
| help_index_data = {'root': {'groups': groups, 'commands': commands}} |
There was a problem hiding this comment.
compared with command index, why we need 2 extra layers (root, groups) here?
Related command
az help/az --helpDescription
ADO Item: https://msazure.visualstudio.com/One/_workitems/edit/35870312
Testing Guide
Checklist:
helpoutput matches incumbent top-levelhelpoutputhelpis called/used when available/validhelptelemetry is preserved in cached/fallback paths equallyazandazcommandIndexrebuildPerformance degradation of command index rebuild:
This
feature-branchdevbranch:Summary:
There is a small performance degradation of the command index rebuild of around 0.1 of a second. This represents a ~2.5% degradation in performance.
==============
Example of the
helpIndex: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.