Skip to content

{Core} Use commandIndex caching to improve performance of top-level help commands#32637

Open
DanielMicrosoft wants to merge 35 commits intoAzure:devfrom
DanielMicrosoft:35870312-top-level-help-perf
Open

{Core} Use commandIndex caching to improve performance of top-level help commands#32637
DanielMicrosoft wants to merge 35 commits intoAzure:devfrom
DanielMicrosoft:35870312-top-level-help-perf

Conversation

@DanielMicrosoft
Copy link
Contributor

@DanielMicrosoft DanielMicrosoft commented Jan 14, 2026

Related command
az help / az --help

Description

ADO Item: https://msazure.visualstudio.com/One/_workitems/edit/35870312

Testing Guide

Checklist:

  • Top-level help output matches incumbent top-level help output
  • Module/command-level help unaffected
  • Cache (fast) top-level help is called/used when available/valid
  • Fallback to loading all modules when cache invalid
  • help telemetry is preserved in cached/fallback paths equally
  • compare with az and az
  • Measure degradation (if any) in perf of commandIndex rebuild

Performance degradation of command index rebuild:

This feature-branch

Measuring 'az VERSION' performance (triggers cache rebuild)
Iterations: 10
Branch: 35870312-top-level-help-perf

Run 1/10 : 5.208s
Run 2/10 : 5.024s
Run 3/10 : 5.199s
Run 4/10 : 5.090s
Run 5/10 : 5.042s
Run 6/10 : 5.050s
Run 7/10 : 5.143s
Run 8/10 : 5.443s
Run 9/10 : 5.121s
Run 10/10 : 5.131s

Results:
  Average : 5.145s
  Min     : 5.024s
  Max     : 5.443s
  Std Dev : 0.116s

dev branch:

Measuring 'az VERSION' performance (triggers cache rebuild)
Iterations: 10
Branch: dev

Run 1/10 : 5.342s
Run 2/10 : 4.971s
Run 3/10 : 4.955s
Run 4/10 : 4.921s
Run 5/10 : 4.864s
Run 6/10 : 5.032s
Run 7/10 : 4.956s
Run 8/10 : 5.036s
Run 9/10 : 5.137s
Run 10/10 : 4.995s

Results:
  Average : 5.021s
  Min     : 4.864s
  Max     : 5.342s
  Std Dev : 0.128s

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:

"helpIndex": {
    "root": {
      "groups": {
        "advisor": { "summary": "Manage Azure Advisor.", "tags": "" },
        "ams": {
          "summary": "Manage Azure Media Services resources.",
          "tags": ""
        },
        "appconfig": { "summary": "Manage App Configurations.", "tags": "" },
        "apim": {
          "summary": "Manage Azure API Management services.",
          "tags": ""
        },
        "acr": {
          "summary": "Manage private registries with Azure Container Registries.",
          "tags": ""
        },
        "aro": {
          "summary": "Manage Azure Red Hat OpenShift clusters.",
          "tags": ""
        },
        "backup": { "summary": "Manage Azure Backups.", "tags": "" },
        "batch": { "summary": "Manage Azure Batch.", "tags": "" },
        "appservice": { "summary": "Manage Appservice.", "tags": "" },
        "webapp": { "summary": "Manage web apps.", "tags": "" },
        "functionapp": {
          "summary": "Manage function apps. To install the Azure Functions Core tools see https://github.com/Azure/azure-functions-core-tools.",
          "tags": ""
        },
        "staticwebapp": { "summary": "Manage static apps.", "tags": "" },
        "logicapp": { "summary": "Manage logic apps.", "tags": "" },
        "bot": { "summary": "Manage Microsoft Azure Bot Service.", "tags": "" },
        "cloud": { "summary": "Manage registered Azure clouds.", "tags": "" },
        "cognitiveservices": {
          "summary": "Manage Azure Cognitive Services accounts.",
          "tags": ""
        },
        "billing": { "summary": "Manage Azure Billing.", "tags": "" },
        "compute-recommender": {
          "summary": "Manage sku/zone/region recommender info for compute resources.",
          "tags": ""
        },
        "config": {
          "summary": "Manage Azure CLI configuration.",
          "tags": "[Experimental]"
        },
        "compute-fleet": {
          "summary": "Manage for Azure Compute Fleet.",
          "tags": "[Preview]"
        },
        "cache": {
          "summary": "Commands to manage CLI objects cached using the `--defer` argument.",
          "tags": ""
        },
        "container": {
          "summary": "Manage Azure Container Instances.",
          "tags": ""
        },
        "consumption": {
          "summary": "Manage consumption of Azure resources.",
          "tags": "[Preview]"
        },
        "aks": { "summary": "Azure Kubernetes Service.", "tags": "" },
        "cosmosdb": {
          "summary": "Manage Azure Cosmos DB database accounts.",
          "tags": ""
        },
        "managed-cassandra": {
          "summary": "Azure Managed Cassandra.",
          "tags": ""
        },
        "dls": {
          "summary": "Manage Data Lake Store accounts and filesystems.",
          "tags": "[Preview]"
        },
        "databoxedge": {
          "summary": "Manage device with databoxedge.",
          "tags": ""
        },
        "dms": {
          "summary": "Manage Azure Data Migration Service (classic) instances.",
          "tags": ""
        },
        "eventgrid": {
          "summary": "Manage Azure Event Grid topics, domains, domain topics, system topics partner topics, event subscriptions, system topic event subscriptions and partner topic event subscriptions.",
          "tags": ""
        },
        "extension": {
          "summary": "Manage and update CLI extensions.",
          "tags": ""
        },
        "hdinsight": { "summary": "Manage HDInsight resources.", "tags": "" },
        "eventhubs": { "summary": "Eventhubs.", "tags": "" },
        "identity": { "summary": "Manage Managed Identity.", "tags": "" },
        "keyvault": {
          "summary": "Manage KeyVault keys, secrets, and certificates.",
          "tags": ""
        },
        "lab": { "summary": "Manage azure devtest labs.", "tags": "[Preview]" },
        "iot": {
          "summary": "Manage Internet of Things (IoT) assets.",
          "tags": ""
        },
        "managedservices": {
          "summary": "Manage the registration assignments and definitions in Azure.",
          "tags": ""
        },
        "maps": { "summary": "Manage Azure Maps.", "tags": "" },
        "containerapp": {
          "summary": "Manage Azure Container Apps.",
          "tags": ""
        },
        "term": {
          "summary": "Manage marketplace agreement with marketplaceordering.",
          "tags": "[Experimental]"
        },
        "afd": {
          "summary": "Manage Azure Front Door Standard/Premium.",
          "tags": ""
        },
        "cdn": {
          "summary": "Manage Azure Content Delivery Networks (CDNs).",
          "tags": ""
        },
        "netappfiles": {
          "summary": "Manage Azure NetApp Files (ANF) Resources.",
          "tags": ""
        },
        "mysql": {
          "summary": "Manage Azure Database for MySQL servers.",
          "tags": ""
        },
        "policy": {
          "summary": "Manage resources defined and used by the Azure Policy service.",
          "tags": ""
        },
        "network": { "summary": "Manage Azure Network resources.", "tags": "" },
        "account": {
          "summary": "Manage Azure subscription information.",
          "tags": ""
        },
        "postgres": {
          "summary": "Manage Azure Database for PostgreSQL.",
          "tags": ""
        },
        "redis": {
          "summary": "Manage dedicated Redis caches for your Azure applications.",
          "tags": ""
        },
        "mariadb": {
          "summary": "Manage Azure Database for MariaDB servers.",
          "tags": ""
        },
        "relay": {
          "summary": "Manage Azure Relay Service namespaces, WCF relays, hybrid connections, and rules.",
          "tags": ""
        },
        "role": {
          "summary": "Manage Azure role-based access control (Azure RBAC).",
          "tags": ""
        },
        "ad": {
          "summary": "Manage Microsoft Entra ID (formerly known as Azure Active Directory, Azure AD, AAD) entities needed for Azure role-based access control (Azure RBAC) through Microsoft Graph API.",
          "tags": ""
        },
        "search": { "summary": "Manage Search.", "tags": "" },
        "security": {
          "summary": "Manage your security posture with Microsoft Defender for Cloud.",
          "tags": ""
        },
        "data-boundary": { "summary": "Data boundary operations.", "tags": "" },
        "group": {
          "summary": "Manage resource groups and template deployments.",
          "tags": ""
        },
        "resource": { "summary": "Manage Azure resources.", "tags": "" },
        "provider": { "summary": "Manage resource providers.", "tags": "" },
        "feature": {
          "summary": "Manage resource provider features.",
          "tags": ""
        },
        "tag": { "summary": "Tag Management on a resource.", "tags": "" },
        "deployment": {
          "summary": "Manage Azure Resource Manager template deployment at subscription scope.",
          "tags": ""
        },
        "deployment-scripts": {
          "summary": "Manage deployment scripts at subscription or resource group scope.",
          "tags": ""
        },
        "ts": {
          "summary": "Manage template specs at subscription or resource group scope.",
          "tags": ""
        },
        "stack": {
          "summary": "A deployment stack is a native Azure resource type that enables you to perform operations on a resource collection as an atomic unit.",
          "tags": ""
        },
        "lock": { "summary": "Manage Azure locks.", "tags": "" },
        "managedapp": {
          "summary": "Manage template solutions provided and maintained by Independent Software Vendors (ISVs).",
          "tags": ""
        },
        "bicep": { "summary": "Bicep CLI command group.", "tags": "" },
        "resourcemanagement": {
          "summary": "Resourcemanagement CLI command group.",
          "tags": ""
        },
        "private-link": {
          "summary": "Private-link association CLI command group.",
          "tags": ""
        },
        "servicebus": { "summary": "Servicebus.", "tags": "" },
        "sf": {
          "summary": "Manage and administer Azure Service Fabric clusters.",
          "tags": ""
        },
        "signalr": { "summary": "Manage Azure SignalR Service.", "tags": "" },
        "sql": {
          "summary": "Manage Azure SQL Databases and Data Warehouses.",
          "tags": ""
        },
        "storage": {
          "summary": "Manage Azure Cloud Storage resources.",
          "tags": ""
        },
        "synapse": {
          "summary": "Manage and operate Synapse Workspace, Spark Pool, SQL Pool.",
          "tags": ""
        },
        "connection": {
          "summary": "Commands to manage Service Connector local connections which allow local environment to connect Azure Resource. If you want to manage connection for compute service, please run 'az webapp/containerapp/spring connection'.",
          "tags": ""
        },
        "capacity": { "summary": "Manage capacity.", "tags": "" },
        "disk": { "summary": "Manage Azure Managed Disks.", "tags": "" },
        "disk-access": {
          "summary": "Manage disk access resources.",
          "tags": ""
        },
        "disk-encryption-set": {
          "summary": "Disk Encryption Set resource.",
          "tags": ""
        },
        "image": {
          "summary": "Manage custom virtual machine images.",
          "tags": ""
        },
        "ppg": { "summary": "Manage Proximity Placement Groups.", "tags": "" },
        "restore-point": {
          "summary": "Manage restore point with res.",
          "tags": ""
        },
        "sig": { "summary": "Manage shared image gallery.", "tags": "" },
        "snapshot": {
          "summary": "Manage point-in-time copies of managed disks, native blobs, or other snapshots.",
          "tags": ""
        },
        "vm": {
          "summary": "Manage Linux or Windows virtual machines.",
          "tags": ""
        },
        "vmss": {
          "summary": "Manage groupings of virtual machines in an Azure Virtual Machine Scale Set (VMSS).",
          "tags": ""
        },
        "sshkey": { "summary": "Manage ssh public key with vm.", "tags": "" },
        "monitor": {
          "summary": "Manage the Azure Monitor Service.",
          "tags": ""
        },
        "devops": {
          "summary": "Manage Azure DevOps organization level operations.",
          "tags": ""
        },
        "boards": { "summary": "Manage Azure Boards.", "tags": "" },
        "pipelines": { "summary": "Manage Azure Pipelines.", "tags": "" },
        "repos": { "summary": "Manage Azure Repos.", "tags": "" },
        "artifacts": { "summary": "Manage Azure Artifacts.", "tags": "" },
        "ssh": {
          "summary": "SSH into resources (Azure VMs, Arc servers, etc) using AAD issued openssh certificates.",
          "tags": ""
        }
      },
      "commands": {
        "configure": {
          "summary": "Manage Azure CLI configuration. This command is interactive.",
          "tags": ""
        },
        "feedback": {
          "summary": "Send feedback to the Azure CLI Team.",
          "tags": ""
        },
        "survey": { "summary": "Take Azure CLI survey.", "tags": "" },
        "find": {
          "summary": "I'm an AI robot, my advice is based on our Azure documentation as well as the usage patterns of Azure CLI and Azure ARM users. Using me improves Azure products and documentation.",
          "tags": ""
        },
        "interactive": {
          "summary": "Start interactive mode. Installs the Interactive extension if not installed already.",
          "tags": "[Preview]"
        },
        "login": { "summary": "Log in to Azure.", "tags": "" },
        "logout": {
          "summary": "Log out to remove access to Azure subscriptions.",
          "tags": ""
        },
        "rest": { "summary": "Invoke a custom request.", "tags": "" },
        "version": {
          "summary": "Show the versions of Azure CLI modules and extensions in JSON format by default or format configured by --output.",
          "tags": ""
        },
        "upgrade": {
          "summary": "Upgrade Azure CLI and extensions.",
          "tags": "[Preview]"
        }
      }
    }
  }

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.

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

azure-client-tools-bot-prd bot commented Jan 14, 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 Jan 14, 2026

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

@yonzhan
Copy link
Collaborator

yonzhan commented Jan 14, 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>

@microsoft-github-policy-service microsoft-github-policy-service bot added Auto-Assign Auto assign by bot Core CLI core infrastructure labels Jan 14, 2026
@jiasli jiasli assigned DanielMicrosoft and unassigned jiasli Jan 19, 2026
@DanielMicrosoft DanielMicrosoft changed the title {Core} Use commandIndex caching to improve performance of top-level help command {Core} Use commandIndex caching to improve performance of top-level and module-level help commands Jan 22, 2026
@DanielMicrosoft DanielMicrosoft changed the title {Core} Use commandIndex caching to improve performance of top-level and module-level help commands {Core} Use commandIndex caching to improve performance of top-level help commands Feb 12, 2026
… 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)
@DanielMicrosoft DanielMicrosoft force-pushed the 35870312-top-level-help-perf branch from 478fac6 to 16d1c57 Compare February 12, 2026 01:23
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 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.

@necusjz
Copy link
Member

necusjz commented Feb 18, 2026

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}}
Copy link
Member

Choose a reason for hiding this comment

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

compared with command index, why we need 2 extra layers (root, groups) here?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments